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 wid = ntohl (wvm->wid);
445 if (wid >= h->watches_size)
448 return GNUNET_SYSERR;
451 (void) w->proc (w->proc_cls,
454 GNUNET_ntohll (wvm->value),
456 (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
462 * Function called with messages from stats service.
465 * @param msg message received, NULL on timeout or fatal error
468 receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
470 struct GNUNET_STATISTICS_Handle *h = cls;
474 if (NULL != h->client)
476 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
481 "Error receiving statistics from service, is the service running?\n" );
483 finish (h, GNUNET_SYSERR);
486 switch (ntohs (msg->type))
488 case GNUNET_MESSAGE_TYPE_STATISTICS_END:
490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
491 "Received end of statistics marker\n");
493 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
494 if (h->watches_size > 0)
496 GNUNET_CLIENT_receive (h->client,
499 GNUNET_TIME_UNIT_FOREVER_REL);
503 h->receiving = GNUNET_NO;
505 finish (h, GNUNET_OK);
507 case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
508 if (GNUNET_OK == process_message (h, msg))
510 /* finally, look for more! */
512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
513 "Processing VALUE done, now reading more\n");
515 GNUNET_CLIENT_receive (h->client,
518 GNUNET_TIME_absolute_get_remaining
519 (h->current->timeout));
520 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
525 case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
527 process_watch_value (h,
530 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
531 GNUNET_assert (h->watches_size > 0);
532 GNUNET_CLIENT_receive (h->client,
535 GNUNET_TIME_UNIT_FOREVER_REL);
544 if (NULL != h->client)
546 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
549 finish (h, GNUNET_SYSERR);
554 * Transmit a GET request (and if successful, start to receive
558 transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
560 struct GNUNET_MessageHeader *hdr;
567 /* timeout / error */
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
570 "Transmission of request for statistics failed!\n");
572 finish (handle, GNUNET_SYSERR);
575 slen1 = strlen (handle->current->subsystem) + 1;
576 slen2 = strlen (handle->current->name) + 1;
577 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
578 GNUNET_assert (msize <= size);
579 hdr = (struct GNUNET_MessageHeader *) buf;
580 hdr->size = htons (msize);
581 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET);
582 GNUNET_assert (slen1 + slen2 ==
583 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
586 handle->current->subsystem,
587 handle->current->name));
588 if (! handle->receiving)
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
592 "Transmission of GET done, now reading response\n");
594 handle->receiving = GNUNET_YES;
595 GNUNET_CLIENT_receive (handle->client,
598 GNUNET_TIME_absolute_get_remaining (handle->
606 * Transmit a WATCH request (and if successful, start to receive
610 transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
612 struct GNUNET_MessageHeader *hdr;
619 /* timeout / error */
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
622 "Transmission of request for statistics failed!\n");
624 finish (handle, GNUNET_SYSERR);
627 slen1 = strlen (handle->current->subsystem) + 1;
628 slen2 = strlen (handle->current->name) + 1;
629 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
630 GNUNET_assert (msize <= size);
631 hdr = (struct GNUNET_MessageHeader *) buf;
632 hdr->size = htons (msize);
633 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
634 GNUNET_assert (slen1 + slen2 ==
635 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
638 handle->current->subsystem,
639 handle->current->name));
640 if (! handle->receiving)
642 handle->receiving = GNUNET_YES;
643 GNUNET_CLIENT_receive (handle->client,
646 GNUNET_TIME_UNIT_FOREVER_REL);
653 * Transmit a SET/UPDATE request.
656 transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
658 struct GNUNET_STATISTICS_SetMessage *r;
665 finish (handle, GNUNET_SYSERR);
669 slen = strlen (handle->current->subsystem) + 1;
670 nlen = strlen (handle->current->name) + 1;
671 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
675 finish (handle, GNUNET_SYSERR);
679 r->header.size = htons (nsize);
680 r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
682 r->value = GNUNET_htonll (handle->current->value);
683 if (handle->current->make_persistent)
684 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_PERSISTENT);
685 if (handle->current->type == ACTION_UPDATE)
686 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
687 GNUNET_assert (slen + nlen ==
688 GNUNET_STRINGS_buffer_fill ((char *) &r[1],
691 handle->current->subsystem,
692 handle->current->name));
693 finish (handle, GNUNET_OK);
699 transmit_action (void *cls, size_t size, void *buf)
701 struct GNUNET_STATISTICS_Handle *handle = cls;
705 switch (handle->current->type)
708 ret = transmit_get (handle, size, buf);
712 ret = transmit_set (handle, size, buf);
715 ret = transmit_watch (handle, size, buf);
727 * Get handle for the statistics service.
729 * @param sched scheduler to use
730 * @param subsystem name of subsystem using the service
731 * @param cfg services configuration in use
732 * @return handle to use
734 struct GNUNET_STATISTICS_Handle *
735 GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched,
736 const char *subsystem,
737 const struct GNUNET_CONFIGURATION_Handle *cfg)
739 struct GNUNET_STATISTICS_Handle *ret;
741 GNUNET_assert (subsystem != NULL);
742 GNUNET_assert (sched != NULL);
743 GNUNET_assert (cfg != NULL);
744 ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle));
747 ret->subsystem = GNUNET_strdup (subsystem);
748 ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
755 * Destroy a handle (free all state associated with
758 * @param h statistics handle to destroy
759 * @param sync_first set to GNUNET_YES if pending SET requests should
763 GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
766 struct GNUNET_STATISTICS_GetHandle *pos;
767 struct GNUNET_STATISTICS_GetHandle *next;
768 struct GNUNET_STATISTICS_GetHandle *prev;
769 struct GNUNET_TIME_Relative timeout;
772 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
773 GNUNET_SCHEDULER_cancel (h->sched,
777 if (h->current != NULL)
779 if (h->current->type == ACTION_GET)
781 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
783 free_action_item (h->current);
787 pos = h->action_head;
792 if (pos->type == ACTION_GET)
795 h->action_head = next;
798 free_action_item (pos);
806 h->action_tail = prev;
807 if (h->current == NULL)
809 h->current = h->action_head;
810 if (h->action_head != NULL)
812 h->action_head = h->action_head->next;
813 if (h->action_head == NULL)
814 h->action_tail = NULL;
817 h->do_destroy = GNUNET_YES;
818 if ( (h->current != NULL) &&
821 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
822 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
826 &transmit_action, h);
827 GNUNET_assert (NULL != h->th);
834 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
837 if (h->current != NULL)
838 free_action_item (h->current);
839 while (NULL != (pos = h->action_head))
841 h->action_head = pos->next;
842 free_action_item (pos);
844 if (h->client != NULL)
846 GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
849 for (i=0;i<h->watches_size;i++)
851 GNUNET_free (h->watches[i]->subsystem);
852 GNUNET_free (h->watches[i]->name);
853 GNUNET_free (h->watches[i]);
855 GNUNET_array_grow (h->watches,
858 GNUNET_free (h->subsystem);
864 finish_task (void *cls,
865 const struct GNUNET_SCHEDULER_TaskContext *tc)
867 struct GNUNET_STATISTICS_Handle *h = cls;
869 h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
870 finish (h, GNUNET_SYSERR);
875 * Schedule the next action to be performed.
878 schedule_action (struct GNUNET_STATISTICS_Handle *h)
880 struct GNUNET_TIME_Relative timeout;
882 if (h->current != NULL)
883 return; /* action already pending */
884 if (GNUNET_YES != try_connect (h))
886 h->backoff_task = GNUNET_SCHEDULER_add_delayed (h->sched,
890 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
891 h->backoff = GNUNET_TIME_relative_min (h->backoff,
892 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
896 /* schedule next action */
897 h->current = h->action_head;
898 if (NULL == h->current)
902 h->do_destroy = GNUNET_NO;
903 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
907 GNUNET_CONTAINER_DLL_remove (h->action_head,
910 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
912 (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
916 &transmit_action, h)))
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
920 "Failed to transmit request to statistics service.\n");
922 finish (h, GNUNET_SYSERR);
927 * Get statistic from the peer.
929 * @param handle identification of the statistics service
930 * @param subsystem limit to the specified subsystem, NULL for our subsystem
931 * @param name name of the statistic value, NULL for all values
932 * @param timeout after how long should we give up (and call
933 * cont with an error code)?
934 * @param cont continuation to call when done (can be NULL)
935 * @param proc function to call on each value
936 * @param cls closure for cont and proc
937 * @return NULL on error
939 struct GNUNET_STATISTICS_GetHandle *
940 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
941 const char *subsystem,
943 struct GNUNET_TIME_Relative timeout,
944 GNUNET_STATISTICS_Callback cont,
945 GNUNET_STATISTICS_Iterator proc, void *cls)
949 struct GNUNET_STATISTICS_GetHandle *ai;
951 GNUNET_assert (handle != NULL);
952 GNUNET_assert (proc != NULL);
953 GNUNET_assert (GNUNET_NO == handle->do_destroy);
954 if (GNUNET_YES != try_connect (handle))
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
958 "Failed to connect to statistics service, can not get value `%s:%s'.\n",
959 strlen (subsystem) ? subsystem : "*",
960 strlen (name) ? name : "*");
964 if (subsystem == NULL)
968 slen1 = strlen (subsystem) + 1;
969 slen2 = strlen (name) + 1;
970 GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) <
971 GNUNET_SERVER_MAX_MESSAGE_SIZE);
972 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
974 ai->subsystem = GNUNET_strdup (subsystem);
975 ai->name = GNUNET_strdup (name);
979 ai->timeout = GNUNET_TIME_relative_to_absolute (timeout);
980 ai->type = ACTION_GET;
981 ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
982 insert_ai (handle, ai);
988 * Cancel a 'get' request. Must be called before the 'cont'
989 * function is called.
991 * @param gh handle of the request to cancel
994 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
996 if (gh->sh->current == gh)
998 gh->aborted = GNUNET_YES;
1002 GNUNET_CONTAINER_DLL_remove (gh->sh->action_head,
1003 gh->sh->action_tail,
1005 GNUNET_free (gh->name);
1006 GNUNET_free (gh->subsystem);
1013 * Watch statistics from the peer (be notified whenever they change).
1014 * Note that the only way to cancel a "watch" request is to destroy
1015 * the statistics handle given as the first argument to this call.
1017 * @param handle identification of the statistics service
1018 * @param subsystem limit to the specified subsystem, never NULL
1019 * @param name name of the statistic value, never NULL
1020 * @param proc function to call on each value
1021 * @param proc_cls closure for proc
1022 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1025 GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1026 const char *subsystem,
1028 GNUNET_STATISTICS_Iterator proc,
1031 struct GNUNET_STATISTICS_WatchEntry *w;
1033 w = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_WatchEntry));
1034 w->subsystem = GNUNET_strdup (subsystem);
1035 w->name = GNUNET_strdup (name);
1037 w->proc_cls = proc_cls;
1038 GNUNET_array_append (handle->watches,
1039 handle->watches_size,
1041 schedule_watch_request (handle, w);
1047 add_setter_action (struct GNUNET_STATISTICS_Handle *h,
1049 int make_persistent,
1050 uint64_t value, enum ActionType type)
1052 struct GNUNET_STATISTICS_GetHandle *ai;
1058 GNUNET_assert (h != NULL);
1059 GNUNET_assert (name != NULL);
1060 if (GNUNET_YES != try_connect (h))
1062 slen = strlen (h->subsystem) + 1;
1063 nlen = strlen (name) + 1;
1064 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
1065 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1070 ai = h->action_head;
1073 if ( (0 == strcmp (ai->subsystem, h->subsystem)) &&
1074 (0 == strcmp (ai->name, name)) &&
1075 ( (ai->type == ACTION_UPDATE) ||
1076 (ai->type == ACTION_SET) ) )
1078 if (ai->type == ACTION_SET)
1080 if (type == ACTION_UPDATE)
1082 delta = (int64_t) value;
1089 if (ai->value < -delta)
1102 if (type == ACTION_UPDATE)
1104 delta = (int64_t) value;
1113 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1114 ai->make_persistent = make_persistent;
1119 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
1121 ai->subsystem = GNUNET_strdup (h->subsystem);
1122 ai->name = GNUNET_strdup (name);
1123 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1124 ai->make_persistent = make_persistent;
1133 * Set statistic value for the peer. Will always use our
1134 * subsystem (the argument used when "handle" was created).
1136 * @param handle identification of the statistics service
1137 * @param name name of the statistic value
1138 * @param value new value to set
1139 * @param make_persistent should the value be kept across restarts?
1142 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1144 uint64_t value, int make_persistent)
1148 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1149 add_setter_action (handle, name, make_persistent, value, ACTION_SET);
1154 * Set statistic value for the peer. Will always use our
1155 * subsystem (the argument used when "handle" was created).
1157 * @param handle identification of the statistics service
1158 * @param name name of the statistic value
1159 * @param delta change in value (added to existing value)
1160 * @param make_persistent should the value be kept across restarts?
1163 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1165 int64_t delta, int make_persistent)
1171 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1172 add_setter_action (handle, name, make_persistent,
1173 (uint64_t) delta, ACTION_UPDATE);
1177 /* end of statistics_api.c */