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
170 * Name of our subsystem.
175 * Configuration to use.
177 const struct GNUNET_CONFIGURATION_Handle *cfg;
180 * Socket (if available).
182 struct GNUNET_CLIENT_Connection *client;
185 * Currently pending transmission request.
187 struct GNUNET_CLIENT_TransmitHandle *th;
190 * Head of the linked list of pending actions (first action
193 struct GNUNET_STATISTICS_GetHandle *action_head;
196 * Tail of the linked list of actions (for fast append).
198 struct GNUNET_STATISTICS_GetHandle *action_tail;
201 * Action we are currently busy with (action request has been
202 * transmitted, we're now receiving the response from the
205 struct GNUNET_STATISTICS_GetHandle *current;
208 * Array of watch entries.
210 struct GNUNET_STATISTICS_WatchEntry **watches;
213 * Task doing exponential back-off trying to reconnect.
215 GNUNET_SCHEDULER_TaskIdentifier backoff_task;
218 * Time for next connect retry.
220 struct GNUNET_TIME_Relative backoff;
223 * Size of the 'watches' array.
225 unsigned int watches_size;
228 * Should this handle auto-destruct once all actions have
234 * Are we currently receiving from the service?
243 * Schedule the next action to be performed.
245 static void schedule_action (struct GNUNET_STATISTICS_Handle *h);
248 * Try to (re)connect to the statistics service.
250 * @return GNUNET_YES on success, GNUNET_NO on failure.
253 try_connect (struct GNUNET_STATISTICS_Handle *ret);
257 insert_ai (struct GNUNET_STATISTICS_Handle *h, struct GNUNET_STATISTICS_GetHandle *ai)
259 GNUNET_CONTAINER_DLL_insert_after (h->action_head,
263 if (h->action_head == ai)
269 schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
270 struct GNUNET_STATISTICS_WatchEntry *watch)
273 struct GNUNET_STATISTICS_GetHandle *ai;
278 GNUNET_assert (h != NULL);
279 if (GNUNET_YES != try_connect (h))
284 slen = strlen (watch->subsystem) + 1;
285 nlen = strlen (watch->name) + 1;
286 nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen;
287 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
292 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
294 ai->subsystem = GNUNET_strdup (watch->subsystem);
295 ai->name = GNUNET_strdup (watch->name);
296 ai->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
298 ai->type = ACTION_WATCH;
299 ai->proc = watch->proc;
300 ai->cls = watch->proc_cls;
306 * Try to (re)connect to the statistics service.
308 * @return GNUNET_YES on success, GNUNET_NO on failure.
311 try_connect (struct GNUNET_STATISTICS_Handle *ret)
314 if (ret->client != NULL)
316 ret->client = GNUNET_CLIENT_connect ("statistics", ret->cfg);
317 if (ret->client != NULL)
319 for (i=0;i<ret->watches_size;i++)
320 schedule_watch_request (ret, ret->watches[i]);
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
325 _("Failed to connect to statistics service!\n"));
332 * Free memory associated with the given action item.
335 free_action_item (struct GNUNET_STATISTICS_GetHandle *ai)
337 GNUNET_free_non_null (ai->subsystem);
338 GNUNET_free_non_null (ai->name);
344 * GET processing is complete, tell client about it.
347 finish (struct GNUNET_STATISTICS_Handle *h, int code)
349 struct GNUNET_STATISTICS_GetHandle *pos = h->current;
354 if (pos->cont != NULL)
355 pos->cont (pos->cls, code);
356 free_action_item (pos);
362 * Process the message.
364 * @return GNUNET_OK if the message was well-formed
367 process_message (struct GNUNET_STATISTICS_Handle *h,
368 const struct GNUNET_MessageHeader *msg)
372 const struct GNUNET_STATISTICS_ReplyMessage *smsg;
375 if (h->current->aborted)
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
379 "Iteration was aborted, ignoring VALUE\n");
381 return GNUNET_OK; /* don't bother */
383 size = ntohs (msg->size);
384 if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage))
387 return GNUNET_SYSERR;
389 smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg;
390 size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
391 if (size != GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1],
392 size, 2, &service, &name))
395 return GNUNET_SYSERR;
398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
399 "Received valid statistic on `%s:%s': %llu\n",
400 service, name, GNUNET_ntohll (smsg->value));
403 h->current->proc (h->current->cls,
406 GNUNET_ntohll (smsg->value),
408 (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Processing of remaining statistics aborted by client.\n");
414 h->current->aborted = GNUNET_YES;
417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
418 "VALUE processed successfully\n");
425 process_watch_value (struct GNUNET_STATISTICS_Handle *h,
426 const struct GNUNET_MessageHeader *msg)
428 const struct GNUNET_STATISTICS_WatchValueMessage *wvm;
429 struct GNUNET_STATISTICS_WatchEntry *w;
432 if (sizeof(struct GNUNET_STATISTICS_WatchValueMessage) !=
436 return GNUNET_SYSERR;
438 wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *)msg;
439 GNUNET_break (0 == ntohl (wvm->reserved));
440 wid = ntohl (wvm->wid);
441 if (wid >= h->watches_size)
444 return GNUNET_SYSERR;
447 (void) w->proc (w->proc_cls,
450 GNUNET_ntohll (wvm->value),
452 (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
458 * Function called with messages from stats service.
461 * @param msg message received, NULL on timeout or fatal error
464 receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
466 struct GNUNET_STATISTICS_Handle *h = cls;
470 if (NULL != h->client)
472 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
477 "Error receiving statistics from service, is the service running?\n" );
479 finish (h, GNUNET_SYSERR);
482 switch (ntohs (msg->type))
484 case GNUNET_MESSAGE_TYPE_STATISTICS_END:
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
487 "Received end of statistics marker\n");
489 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
490 if (h->watches_size > 0)
492 GNUNET_CLIENT_receive (h->client,
495 GNUNET_TIME_UNIT_FOREVER_REL);
499 h->receiving = GNUNET_NO;
501 finish (h, GNUNET_OK);
503 case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
504 if (GNUNET_OK == process_message (h, msg))
506 /* finally, look for more! */
508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
509 "Processing VALUE done, now reading more\n");
511 GNUNET_CLIENT_receive (h->client,
514 GNUNET_TIME_absolute_get_remaining
515 (h->current->timeout));
516 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
521 case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
523 process_watch_value (h,
526 h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
527 GNUNET_assert (h->watches_size > 0);
528 GNUNET_CLIENT_receive (h->client,
531 GNUNET_TIME_UNIT_FOREVER_REL);
540 if (NULL != h->client)
542 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
545 finish (h, GNUNET_SYSERR);
550 * Transmit a GET request (and if successful, start to receive
554 transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
556 struct GNUNET_MessageHeader *hdr;
563 /* timeout / error */
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
566 "Transmission of request for statistics failed!\n");
568 finish (handle, GNUNET_SYSERR);
571 slen1 = strlen (handle->current->subsystem) + 1;
572 slen2 = strlen (handle->current->name) + 1;
573 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
574 GNUNET_assert (msize <= size);
575 hdr = (struct GNUNET_MessageHeader *) buf;
576 hdr->size = htons (msize);
577 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET);
578 GNUNET_assert (slen1 + slen2 ==
579 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
582 handle->current->subsystem,
583 handle->current->name));
584 if (! handle->receiving)
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Transmission of GET done, now reading response\n");
590 handle->receiving = GNUNET_YES;
591 GNUNET_CLIENT_receive (handle->client,
594 GNUNET_TIME_absolute_get_remaining (handle->
602 * Transmit a WATCH request (and if successful, start to receive
606 transmit_watch (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
608 struct GNUNET_MessageHeader *hdr;
615 /* timeout / error */
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
618 "Transmission of request for statistics failed!\n");
620 finish (handle, GNUNET_SYSERR);
623 slen1 = strlen (handle->current->subsystem) + 1;
624 slen2 = strlen (handle->current->name) + 1;
625 msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
626 GNUNET_assert (msize <= size);
627 hdr = (struct GNUNET_MessageHeader *) buf;
628 hdr->size = htons (msize);
629 hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
630 GNUNET_assert (slen1 + slen2 ==
631 GNUNET_STRINGS_buffer_fill ((char *) &hdr[1],
634 handle->current->subsystem,
635 handle->current->name));
636 if (! handle->receiving)
638 handle->receiving = GNUNET_YES;
639 GNUNET_CLIENT_receive (handle->client,
642 GNUNET_TIME_UNIT_FOREVER_REL);
649 * Transmit a SET/UPDATE request.
652 transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
654 struct GNUNET_STATISTICS_SetMessage *r;
661 finish (handle, GNUNET_SYSERR);
665 slen = strlen (handle->current->subsystem) + 1;
666 nlen = strlen (handle->current->name) + 1;
667 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
671 finish (handle, GNUNET_SYSERR);
675 r->header.size = htons (nsize);
676 r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
678 r->value = GNUNET_htonll (handle->current->value);
679 if (handle->current->make_persistent)
680 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_PERSISTENT);
681 if (handle->current->type == ACTION_UPDATE)
682 r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
683 GNUNET_assert (slen + nlen ==
684 GNUNET_STRINGS_buffer_fill ((char *) &r[1],
687 handle->current->subsystem,
688 handle->current->name));
689 finish (handle, GNUNET_OK);
695 transmit_action (void *cls, size_t size, void *buf)
697 struct GNUNET_STATISTICS_Handle *handle = cls;
701 switch (handle->current->type)
704 ret = transmit_get (handle, size, buf);
708 ret = transmit_set (handle, size, buf);
711 ret = transmit_watch (handle, size, buf);
723 * Get handle for the statistics service.
725 * @param subsystem name of subsystem using the service
726 * @param cfg services configuration in use
727 * @return handle to use
729 struct GNUNET_STATISTICS_Handle *
730 GNUNET_STATISTICS_create (const char *subsystem,
731 const struct GNUNET_CONFIGURATION_Handle *cfg)
733 struct GNUNET_STATISTICS_Handle *ret;
735 GNUNET_assert (subsystem != NULL);
736 GNUNET_assert (cfg != NULL);
737 ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle));
739 ret->subsystem = GNUNET_strdup (subsystem);
740 ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
741 if (GNUNET_YES != try_connect (ret))
743 GNUNET_free (ret->subsystem);
752 * Destroy a handle (free all state associated with
755 * @param h statistics handle to destroy
756 * @param sync_first set to GNUNET_YES if pending SET requests should
760 GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
763 struct GNUNET_STATISTICS_GetHandle *pos;
764 struct GNUNET_STATISTICS_GetHandle *next;
765 struct GNUNET_STATISTICS_GetHandle *prev;
766 struct GNUNET_TIME_Relative timeout;
769 if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
770 GNUNET_SCHEDULER_cancel (h->backoff_task);
773 if (h->current != NULL)
775 if (h->current->type == ACTION_GET)
777 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
779 free_action_item (h->current);
783 pos = h->action_head;
788 if (pos->type == ACTION_GET)
791 h->action_head = next;
794 free_action_item (pos);
802 h->action_tail = prev;
803 if (h->current == NULL)
805 h->current = h->action_head;
806 if (h->action_head != NULL)
808 h->action_head = h->action_head->next;
809 if (h->action_head == NULL)
810 h->action_tail = NULL;
813 h->do_destroy = GNUNET_YES;
814 if ( (h->current != NULL) &&
817 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
818 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
822 &transmit_action, h);
823 GNUNET_assert (NULL != h->th);
830 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
833 if (h->current != NULL)
834 free_action_item (h->current);
835 while (NULL != (pos = h->action_head))
837 h->action_head = pos->next;
838 free_action_item (pos);
840 if (h->client != NULL)
842 GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
845 for (i=0;i<h->watches_size;i++)
847 GNUNET_free (h->watches[i]->subsystem);
848 GNUNET_free (h->watches[i]->name);
849 GNUNET_free (h->watches[i]);
851 GNUNET_array_grow (h->watches,
854 GNUNET_free (h->subsystem);
860 finish_task (void *cls,
861 const struct GNUNET_SCHEDULER_TaskContext *tc)
863 struct GNUNET_STATISTICS_Handle *h = cls;
865 h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
866 finish (h, GNUNET_SYSERR);
871 * Schedule the next action to be performed.
874 schedule_action (struct GNUNET_STATISTICS_Handle *h)
876 struct GNUNET_TIME_Relative timeout;
878 if (h->current != NULL)
879 return; /* action already pending */
880 if (GNUNET_YES != try_connect (h))
882 h->backoff_task = GNUNET_SCHEDULER_add_delayed (h->backoff,
885 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
886 h->backoff = GNUNET_TIME_relative_min (h->backoff,
887 GNUNET_CONSTANTS_SERVICE_TIMEOUT);
891 /* schedule next action */
892 h->current = h->action_head;
893 if (NULL == h->current)
897 h->do_destroy = GNUNET_NO;
898 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
902 GNUNET_CONTAINER_DLL_remove (h->action_head,
905 timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
907 (h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
911 &transmit_action, h)))
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
915 "Failed to transmit request to statistics service.\n");
917 finish (h, GNUNET_SYSERR);
922 * Get statistic from the peer.
924 * @param handle identification of the statistics service
925 * @param subsystem limit to the specified subsystem, NULL for our subsystem
926 * @param name name of the statistic value, NULL for all values
927 * @param timeout after how long should we give up (and call
928 * cont with an error code)?
929 * @param cont continuation to call when done (can be NULL)
930 * @param proc function to call on each value
931 * @param cls closure for cont and proc
932 * @return NULL on error
934 struct GNUNET_STATISTICS_GetHandle *
935 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
936 const char *subsystem,
938 struct GNUNET_TIME_Relative timeout,
939 GNUNET_STATISTICS_Callback cont,
940 GNUNET_STATISTICS_Iterator proc, void *cls)
944 struct GNUNET_STATISTICS_GetHandle *ai;
946 GNUNET_assert (handle != NULL);
947 GNUNET_assert (proc != NULL);
948 GNUNET_assert (GNUNET_NO == handle->do_destroy);
949 if (GNUNET_YES != try_connect (handle))
952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
953 "Failed to connect to statistics service, can not get value `%s:%s'.\n",
954 strlen (subsystem) ? subsystem : "*",
955 strlen (name) ? name : "*");
959 if (subsystem == NULL)
963 slen1 = strlen (subsystem) + 1;
964 slen2 = strlen (name) + 1;
965 GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) <
966 GNUNET_SERVER_MAX_MESSAGE_SIZE);
967 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
969 ai->subsystem = GNUNET_strdup (subsystem);
970 ai->name = GNUNET_strdup (name);
974 ai->timeout = GNUNET_TIME_relative_to_absolute (timeout);
975 ai->type = ACTION_GET;
976 ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
977 insert_ai (handle, ai);
983 * Cancel a 'get' request. Must be called before the 'cont'
984 * function is called.
986 * @param gh handle of the request to cancel
989 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
991 if (gh->sh->current == gh)
993 gh->aborted = GNUNET_YES;
997 GNUNET_CONTAINER_DLL_remove (gh->sh->action_head,
1000 GNUNET_free (gh->name);
1001 GNUNET_free (gh->subsystem);
1008 * Watch statistics from the peer (be notified whenever they change).
1009 * Note that the only way to cancel a "watch" request is to destroy
1010 * the statistics handle given as the first argument to this call.
1012 * @param handle identification of the statistics service
1013 * @param subsystem limit to the specified subsystem, never NULL
1014 * @param name name of the statistic value, never NULL
1015 * @param proc function to call on each value
1016 * @param proc_cls closure for proc
1017 * @return GNUNET_OK on success, GNUNET_SYSERR on error
1020 GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1021 const char *subsystem,
1023 GNUNET_STATISTICS_Iterator proc,
1026 struct GNUNET_STATISTICS_WatchEntry *w;
1028 w = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_WatchEntry));
1029 w->subsystem = GNUNET_strdup (subsystem);
1030 w->name = GNUNET_strdup (name);
1032 w->proc_cls = proc_cls;
1033 GNUNET_array_append (handle->watches,
1034 handle->watches_size,
1036 schedule_watch_request (handle, w);
1042 add_setter_action (struct GNUNET_STATISTICS_Handle *h,
1044 int make_persistent,
1045 uint64_t value, enum ActionType type)
1047 struct GNUNET_STATISTICS_GetHandle *ai;
1053 GNUNET_assert (h != NULL);
1054 GNUNET_assert (name != NULL);
1055 if (GNUNET_YES != try_connect (h))
1057 slen = strlen (h->subsystem) + 1;
1058 nlen = strlen (name) + 1;
1059 nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
1060 if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1065 ai = h->action_head;
1068 if ( (0 == strcmp (ai->subsystem, h->subsystem)) &&
1069 (0 == strcmp (ai->name, name)) &&
1070 ( (ai->type == ACTION_UPDATE) ||
1071 (ai->type == ACTION_SET) ) )
1073 if (ai->type == ACTION_SET)
1075 if (type == ACTION_UPDATE)
1077 delta = (int64_t) value;
1084 if (ai->value < -delta)
1097 if (type == ACTION_UPDATE)
1099 delta = (int64_t) value;
1108 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1109 ai->make_persistent = make_persistent;
1114 ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));
1116 ai->subsystem = GNUNET_strdup (h->subsystem);
1117 ai->name = GNUNET_strdup (name);
1118 ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1119 ai->make_persistent = make_persistent;
1128 * Set statistic value for the peer. Will always use our
1129 * subsystem (the argument used when "handle" was created).
1131 * @param handle identification of the statistics service
1132 * @param name name of the statistic value
1133 * @param value new value to set
1134 * @param make_persistent should the value be kept across restarts?
1137 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1139 uint64_t value, int make_persistent)
1143 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1144 add_setter_action (handle, name, make_persistent, value, ACTION_SET);
1149 * Set statistic value for the peer. Will always use our
1150 * subsystem (the argument used when "handle" was created).
1152 * @param handle identification of the statistics service
1153 * @param name name of the statistic value
1154 * @param delta change in value (added to existing value)
1155 * @param make_persistent should the value be kept across restarts?
1158 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1160 int64_t delta, int make_persistent)
1166 GNUNET_assert (GNUNET_NO == handle->do_destroy);
1167 add_setter_action (handle, name, make_persistent,
1168 (uint64_t) delta, ACTION_UPDATE);
1172 /* end of statistics_api.c */