2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file statistics/statistics_api.c
23 * @brief API of the statistics service
24 * @author Christian Grothoff
27 #include "gnunet_client_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_container_lib.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_server_lib.h"
32 #include "gnunet_statistics_service.h"
33 #include "gnunet_strings_lib.h"
34 #include "statistics.h"
37 * How long do we wait until a statistics request for setting
38 * a value times out? (The update will be lost if the
39 * service does not react within this timeframe).
41 #define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
57 * Entry kept for each value we are watching.
59 struct GNUNET_STATISTICS_WatchEntry
63 * What subsystem is this action about? (never NULL)
68 * What value is this action about? (never NULL)
75 GNUNET_STATISTICS_Iterator proc;
86 * Linked list of things we still need to do.
88 struct GNUNET_STATISTICS_GetHandle
92 * This is a doubly linked list.
94 struct GNUNET_STATISTICS_GetHandle *next;
97 * This is a doubly linked list.
99 struct GNUNET_STATISTICS_GetHandle *prev;
102 * Main statistics handle.
104 struct GNUNET_STATISTICS_Handle *sh;
107 * What subsystem is this action about? (can be NULL)
112 * What value is this action about? (can be NULL)
117 * Continuation to call once action is complete.
119 GNUNET_STATISTICS_Callback cont;
122 * Function to call (for GET actions only).
124 GNUNET_STATISTICS_Iterator proc;
127 * Closure for proc and cont.
132 * Timeout for this action.
134 struct GNUNET_TIME_Absolute timeout;
142 * Flag for SET/UPDATE actions.
147 * Has the current iteration been aborted; for GET actions.
152 * Is this a GET, SET, UPDATE or WATCH?
154 enum ActionType type;
157 * Size of the message that we will be transmitting.
165 * Handle for the service.
167 struct GNUNET_STATISTICS_Handle
172 struct GNUNET_SCHEDULER_Handle *sched;
175 * Name of our subsystem.
180 * Configuration to use.
182 const struct GNUNET_CONFIGURATION_Handle *cfg;
185 * Socket (if available).
187 struct GNUNET_CLIENT_Connection *client;
190 * Currently pending transmission request.
192 struct GNUNET_CLIENT_TransmitHandle *th;
195 * Head of the linked list of pending actions (first action
198 struct GNUNET_STATISTICS_GetHandle *action_head;
201 * Tail of the linked list of actions (for fast append).
203 struct GNUNET_STATISTICS_GetHandle *action_tail;
206 * Action we are currently busy with (action request has been
207 * transmitted, we're now receiving the response from the
210 struct GNUNET_STATISTICS_GetHandle *current;
213 * Array of watch entries.
215 struct GNUNET_STATISTICS_WatchEntry **watches;
218 * Task doing exponential back-off trying to reconnect.
220 GNUNET_SCHEDULER_TaskIdentifier backoff_task;
223 * Time for next connect retry.
225 struct GNUNET_TIME_Relative backoff;
228 * Size of the 'watches' array.
230 unsigned int watches_size;
233 * Should this handle auto-destruct once all actions have
239 * Are we currently receiving from the service?
248 * Schedule the next action to be performed.
250 static void schedule_action (struct GNUNET_STATISTICS_Handle *h);
253 * Try to (re)connect to the statistics service.
255 * @return GNUNET_YES on success, GNUNET_NO on failure.
258 try_connect (struct GNUNET_STATISTICS_Handle *ret);
262 insert_ai (struct GNUNET_STATISTICS_Handle *h, struct GNUNET_STATISTICS_GetHandle *ai)
264 GNUNET_CONTAINER_DLL_insert_after (h->action_head,
268 if (h->action_head == ai)
274 schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
275 struct GNUNET_STATISTICS_WatchEntry *watch)
278 struct GNUNET_STATISTICS_GetHandle *ai;
283 GNUNET_assert (h != NULL);
284 if (GNUNET_YES != try_connect (h))
289 slen = strlen (watch->subsystem) + 1;
290 nlen = strlen (watch->name) + 1;
291 nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen;
292 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
297 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
299 ai->subsystem = GNUNET_strdup (watch->subsystem);
300 ai->name = GNUNET_strdup (watch->name);
301 ai->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
303 ai->type = ACTION_WATCH;
304 ai->proc = watch->proc;
305 ai->cls = watch->proc_cls;
311 * Try to (re)connect to the statistics service.
313 * @return GNUNET_YES on success, GNUNET_NO on failure.
316 try_connect (struct GNUNET_STATISTICS_Handle *ret)
319 if (ret->client != NULL)
321 ret->client = GNUNET_CLIENT_connect (ret->sched, "statistics", ret->cfg);
322 if (ret->client != NULL)
324 for (i=0;i<ret->watches_size;i++)
325 schedule_watch_request (ret, ret->watches[i]);
329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
330 _("Failed to connect to statistics service!\n"));
337 * Free memory associated with the given action item.
340 free_action_item (struct GNUNET_STATISTICS_GetHandle *ai)
342 GNUNET_free_non_null (ai->subsystem);
343 GNUNET_free_non_null (ai->name);
349 * GET processing is complete, tell client about it.
352 finish (struct GNUNET_STATISTICS_Handle *h, int code)
354 struct GNUNET_STATISTICS_GetHandle *pos = h->current;
359 if (pos->cont != NULL)
360 pos->cont (pos->cls, code);
361 free_action_item (pos);
367 * Process the message.
369 * @return GNUNET_OK if the message was well-formed
372 process_message (struct GNUNET_STATISTICS_Handle *h,
373 const struct GNUNET_MessageHeader *msg)
377 const struct GNUNET_STATISTICS_ReplyMessage *smsg;
380 if (h->current->aborted)
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
384 "Iteration was aborted, ignoring VALUE\n");
386 return GNUNET_OK; /* don't bother */
388 size = ntohs (msg->size);
389 if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage))
392 return GNUNET_SYSERR;
394 smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg;
395 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
396 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1],
397 size, 2, &service, &name))
400 return GNUNET_SYSERR;
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Received valid statistic on `%s:%s': %llu\n",
405 service, name, GNUNET_ntohll (smsg->value));
408 h->current->proc (h->current->cls,
411 GNUNET_ntohll (smsg->value),
413 (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
417 "Processing of remaining statistics aborted by client.\n");
419 h->current->aborted = GNUNET_YES;
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "VALUE processed successfully\n");
430 process_watch_value (struct GNUNET_STATISTICS_Handle *h,
431 const struct GNUNET_MessageHeader *msg)
433 const struct GNUNET_STATISTICS_WatchValueMessage *wvm;
434 struct GNUNET_STATISTICS_WatchEntry *w;
437 if (sizeof(struct GNUNET_STATISTICS_WatchValueMessage) !=
441 return GNUNET_SYSERR;
443 wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *)msg;
444 GNUNET_break (0 == ntohl (wvm->reserved));
445 wid = ntohl (wvm->wid);
446 if (wid >= h->watches_size)
449 return GNUNET_SYSERR;
452 (void) w->proc (w->proc_cls,
455 GNUNET_ntohll (wvm->value),
457 (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
463 * Function called with messages from stats service.
466 * @param msg message received, NULL on timeout or fatal error
469 receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
471 struct GNUNET_STATISTICS_Handle *h = cls;
475 if (NULL != h->client)
477 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
482 "Error receiving statistics from service, is the service running?\n" );
484 finish (h, GNUNET_SYSERR);
487 switch (ntohs (msg->type))
489 case GNUNET_MESSAGE_TYPE_STATISTICS_END:
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492 "Received end of statistics marker\n");
494 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
495 if (h->watches_size > 0)
497 GNUNET_CLIENT_receive (h->client,
500 GNUNET_TIME_UNIT_FOREVER_REL);
504 h->receiving = GNUNET_NO;
506 finish (h, GNUNET_OK);
508 case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
509 if (GNUNET_OK == process_message (h, msg))
511 /* finally, look for more! */
513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
514 "Processing VALUE done, now reading more\n");
516 GNUNET_CLIENT_receive (h->client,
519 GNUNET_TIME_absolute_get_remaining
520 (h->current->timeout));
521 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
526 case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
528 process_watch_value (h,
531 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
532 GNUNET_assert (h->watches_size > 0);
533 GNUNET_CLIENT_receive (h->client,
536 GNUNET_TIME_UNIT_FOREVER_REL);
545 if (NULL != h->client)
547 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
550 finish (h, GNUNET_SYSERR);
555 * Transmit a GET request (and if successful, start to receive
559 transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
561 struct GNUNET_MessageHeader *hdr;
568 /* timeout / error */
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
571 "Transmission of request for statistics failed!\n");
573 finish (handle, GNUNET_SYSERR);
576 slen1 = strlen (handle->current->subsystem) + 1;
577 slen2 = strlen (handle->current->name) + 1;
578 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
579 GNUNET_assert (msize <= size);
580 hdr = (struct GNUNET_MessageHeader *) buf;
581 hdr->size = htons (msize);
582 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET);
583 GNUNET_assert (slen1 + slen2 ==
584 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
587 handle->current->subsystem,
588 handle->current->name));
589 if (! handle->receiving)
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
593 "Transmission of GET done, now reading response\n");
595 handle->receiving = GNUNET_YES;
596 GNUNET_CLIENT_receive (handle->client,
599 GNUNET_TIME_absolute_get_remaining (handle->
607 * Transmit a WATCH request (and if successful, start to receive
611 transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
613 struct GNUNET_MessageHeader *hdr;
620 /* timeout / error */
622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
623 "Transmission of request for statistics failed!\n");
625 finish (handle, GNUNET_SYSERR);
628 slen1 = strlen (handle->current->subsystem) + 1;
629 slen2 = strlen (handle->current->name) + 1;
630 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
631 GNUNET_assert (msize <= size);
632 hdr = (struct GNUNET_MessageHeader *) buf;
633 hdr->size = htons (msize);
634 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
635 GNUNET_assert (slen1 + slen2 ==
636 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
639 handle->current->subsystem,
640 handle->current->name));
641 if (! handle->receiving)
643 handle->receiving = GNUNET_YES;
644 GNUNET_CLIENT_receive (handle->client,
647 GNUNET_TIME_UNIT_FOREVER_REL);
654 * Transmit a SET/UPDATE request.
657 transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
659 struct GNUNET_STATISTICS_SetMessage *r;
666 finish (handle, GNUNET_SYSERR);
670 slen = strlen (handle->current->subsystem) + 1;
671 nlen = strlen (handle->current->name) + 1;
672 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
676 finish (handle, GNUNET_SYSERR);
680 r->header.size = htons (nsize);
681 r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
683 r->value = GNUNET_htonll (handle->current->value);
684 if (handle->current->make_persistent)
685 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_PERSISTENT);
686 if (handle->current->type == ACTION_UPDATE)
687 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
688 GNUNET_assert (slen + nlen ==
689 GNUNET_STRINGS_buffer_fill ((char *) &r[1],
692 handle->current->subsystem,
693 handle->current->name));
694 finish (handle, GNUNET_OK);
700 transmit_action (void *cls, size_t size, void *buf)
702 struct GNUNET_STATISTICS_Handle *handle = cls;
706 switch (handle->current->type)
709 ret = transmit_get (handle, size, buf);
713 ret = transmit_set (handle, size, buf);
716 ret = transmit_watch (handle, size, buf);
728 * Get handle for the statistics service.
730 * @param sched scheduler to use
731 * @param subsystem name of subsystem using the service
732 * @param cfg services configuration in use
733 * @return handle to use
735 struct GNUNET_STATISTICS_Handle *
736 GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched,
737 const char *subsystem,
738 const struct GNUNET_CONFIGURATION_Handle *cfg)
740 struct GNUNET_STATISTICS_Handle *ret;
742 GNUNET_assert (subsystem != NULL);
743 GNUNET_assert (sched != NULL);
744 GNUNET_assert (cfg != NULL);
745 ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle));
748 ret->subsystem = GNUNET_strdup (subsystem);
749 ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
756 * Destroy a handle (free all state associated with
759 * @param h statistics handle to destroy
760 * @param sync_first set to GNUNET_YES if pending SET requests should
764 GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
767 struct GNUNET_STATISTICS_GetHandle *pos;
768 struct GNUNET_STATISTICS_GetHandle *next;
769 struct GNUNET_STATISTICS_GetHandle *prev;
770 struct GNUNET_TIME_Relative timeout;
773 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
774 GNUNET_SCHEDULER_cancel (h->sched,
778 if (h->current != NULL)
780 if (h->current->type == ACTION_GET)
782 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
784 free_action_item (h->current);
788 pos = h->action_head;
793 if (pos->type == ACTION_GET)
796 h->action_head = next;
799 free_action_item (pos);
807 h->action_tail = prev;
808 if (h->current == NULL)
810 h->current = h->action_head;
811 if (h->action_head != NULL)
813 h->action_head = h->action_head->next;
814 if (h->action_head == NULL)
815 h->action_tail = NULL;
818 h->do_destroy = GNUNET_YES;
819 if ( (h->current != NULL) &&
822 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
823 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
827 &transmit_action, h);
828 GNUNET_assert (NULL != h->th);
835 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
838 if (h->current != NULL)
839 free_action_item (h->current);
840 while (NULL != (pos = h->action_head))
842 h->action_head = pos->next;
843 free_action_item (pos);
845 if (h->client != NULL)
847 GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
850 for (i=0;i<h->watches_size;i++)
852 GNUNET_free (h->watches[i]->subsystem);
853 GNUNET_free (h->watches[i]->name);
854 GNUNET_free (h->watches[i]);
856 GNUNET_array_grow (h->watches,
859 GNUNET_free (h->subsystem);
865 finish_task (void *cls,
866 const struct GNUNET_SCHEDULER_TaskContext *tc)
868 struct GNUNET_STATISTICS_Handle *h = cls;
870 h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
871 finish (h, GNUNET_SYSERR);
876 * Schedule the next action to be performed.
879 schedule_action (struct GNUNET_STATISTICS_Handle *h)
881 struct GNUNET_TIME_Relative timeout;
883 if (h->current != NULL)
884 return; /* action already pending */
885 if (GNUNET_YES != try_connect (h))
887 h->backoff_task = GNUNET_SCHEDULER_add_delayed (h->sched,
891 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
892 h->backoff = GNUNET_TIME_relative_min (h->backoff,
893 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
897 /* schedule next action */
898 h->current = h->action_head;
899 if (NULL == h->current)
903 h->do_destroy = GNUNET_NO;
904 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
908 GNUNET_CONTAINER_DLL_remove (h->action_head,
911 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
913 (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
917 &transmit_action, h)))
920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 "Failed to transmit request to statistics service.\n");
923 finish (h, GNUNET_SYSERR);
928 * Get statistic from the peer.
930 * @param handle identification of the statistics service
931 * @param subsystem limit to the specified subsystem, NULL for our subsystem
932 * @param name name of the statistic value, NULL for all values
933 * @param timeout after how long should we give up (and call
934 * cont with an error code)?
935 * @param cont continuation to call when done (can be NULL)
936 * @param proc function to call on each value
937 * @param cls closure for cont and proc
938 * @return NULL on error
940 struct GNUNET_STATISTICS_GetHandle *
941 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
942 const char *subsystem,
944 struct GNUNET_TIME_Relative timeout,
945 GNUNET_STATISTICS_Callback cont,
946 GNUNET_STATISTICS_Iterator proc, void *cls)
950 struct GNUNET_STATISTICS_GetHandle *ai;
952 GNUNET_assert (handle != NULL);
953 GNUNET_assert (proc != NULL);
954 GNUNET_assert (GNUNET_NO == handle->do_destroy);
955 if (GNUNET_YES != try_connect (handle))
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
959 "Failed to connect to statistics service, can not get value `%s:%s'.\n",
960 strlen (subsystem) ? subsystem : "*",
961 strlen (name) ? name : "*");
965 if (subsystem == NULL)
969 slen1 = strlen (subsystem) + 1;
970 slen2 = strlen (name) + 1;
971 GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) <
972 GNUNET_SERVER_MAX_MESSAGE_SIZE);
973 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
975 ai->subsystem = GNUNET_strdup (subsystem);
976 ai->name = GNUNET_strdup (name);
980 ai->timeout = GNUNET_TIME_relative_to_absolute (timeout);
981 ai->type = ACTION_GET;
982 ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
983 insert_ai (handle, ai);
989 * Cancel a 'get' request. Must be called before the 'cont'
990 * function is called.
992 * @param gh handle of the request to cancel
995 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
997 if (gh->sh->current == gh)
999 gh->aborted = GNUNET_YES;
1003 GNUNET_CONTAINER_DLL_remove (gh->sh->action_head,
1004 gh->sh->action_tail,
1006 GNUNET_free (gh->name);
1007 GNUNET_free (gh->subsystem);
1014 * Watch statistics from the peer (be notified whenever they change).
1015 * Note that the only way to cancel a "watch" request is to destroy
1016 * the statistics handle given as the first argument to this call.
1018 * @param handle identification of the statistics service
1019 * @param subsystem limit to the specified subsystem, never NULL
1020 * @param name name of the statistic value, never NULL
1021 * @param proc function to call on each value
1022 * @param proc_cls closure for proc
1023 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1026 GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1027 const char *subsystem,
1029 GNUNET_STATISTICS_Iterator proc,
1032 struct GNUNET_STATISTICS_WatchEntry *w;
1034 w = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_WatchEntry));
1035 w->subsystem = GNUNET_strdup (subsystem);
1036 w->name = GNUNET_strdup (name);
1038 w->proc_cls = proc_cls;
1039 GNUNET_array_append (handle->watches,
1040 handle->watches_size,
1042 schedule_watch_request (handle, w);
1048 add_setter_action (struct GNUNET_STATISTICS_Handle *h,
1050 int make_persistent,
1051 uint64_t value, enum ActionType type)
1053 struct GNUNET_STATISTICS_GetHandle *ai;
1059 GNUNET_assert (h != NULL);
1060 GNUNET_assert (name != NULL);
1061 if (GNUNET_YES != try_connect (h))
1063 slen = strlen (h->subsystem) + 1;
1064 nlen = strlen (name) + 1;
1065 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
1066 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1071 ai = h->action_head;
1074 if ( (0 == strcmp (ai->subsystem, h->subsystem)) &&
1075 (0 == strcmp (ai->name, name)) &&
1076 ( (ai->type == ACTION_UPDATE) ||
1077 (ai->type == ACTION_SET) ) )
1079 if (ai->type == ACTION_SET)
1081 if (type == ACTION_UPDATE)
1083 delta = (int64_t) value;
1090 if (ai->value < -delta)
1103 if (type == ACTION_UPDATE)
1105 delta = (int64_t) value;
1114 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1115 ai->make_persistent = make_persistent;
1120 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
1122 ai->subsystem = GNUNET_strdup (h->subsystem);
1123 ai->name = GNUNET_strdup (name);
1124 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1125 ai->make_persistent = make_persistent;
1134 * Set statistic value for the peer. Will always use our
1135 * subsystem (the argument used when "handle" was created).
1137 * @param handle identification of the statistics service
1138 * @param name name of the statistic value
1139 * @param value new value to set
1140 * @param make_persistent should the value be kept across restarts?
1143 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1145 uint64_t value, int make_persistent)
1149 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1150 add_setter_action (handle, name, make_persistent, value, ACTION_SET);
1155 * Set statistic value for the peer. Will always use our
1156 * subsystem (the argument used when "handle" was created).
1158 * @param handle identification of the statistics service
1159 * @param name name of the statistic value
1160 * @param delta change in value (added to existing value)
1161 * @param make_persistent should the value be kept across restarts?
1164 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1166 int64_t delta, int make_persistent)
1172 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1173 add_setter_action (handle, name, make_persistent,
1174 (uint64_t) delta, ACTION_UPDATE);
1178 /* end of statistics_api.c */