gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_load_lib.h (3046B)


      1 /*
      2      This file is part of GNUnet.
      3      Copyright (C) 2010 GNUnet e.V.
      4 
      5      GNUnet is free software: you can redistribute it and/or modify it
      6      under the terms of the GNU Affero General Public License as published
      7      by the Free Software Foundation, either version 3 of the License,
      8      or (at your option) any later version.
      9 
     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      Affero General Public License for more details.
     14 
     15      You should have received a copy of the GNU Affero General Public License
     16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18      SPDX-License-Identifier: AGPL3.0-or-later
     19  */
     20 
     21 /**
     22  * @addtogroup libgnunetutil
     23  * @{
     24  *
     25  * @author Christian Grothoff
     26  *
     27  * @file
     28  * Functions related to load calculations
     29  *
     30  * @defgroup load  Load library
     31  * Load calculations.
     32  * @{
     33  */
     34 
     35 #ifndef GNUNET_LOAD_LIB_H
     36 #define GNUNET_LOAD_LIB_H
     37 
     38 #ifdef __cplusplus
     39 extern "C"
     40 {
     41 #if 0                           /* keep Emacsens' auto-indent happy */
     42 }
     43 #endif
     44 #endif
     45 
     46 
     47 #include "gnunet_common.h"
     48 #include "gnunet_time_lib.h"
     49 
     50 /**
     51  * Opaque load handle.
     52  */
     53 struct GNUNET_LOAD_Value;
     54 
     55 /**
     56  * Create a new load value.
     57  *
     58  * @param autodecline speed at which this value should automatically
     59  *        decline in the absence of external events; at the given
     60  *        frequency, 0-load values will be added to the load
     61  * @return the new load value
     62  */
     63 struct GNUNET_LOAD_Value *
     64 GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline);
     65 
     66 
     67 /**
     68  * Change the value by which the load automatically declines.
     69  *
     70  * @param load load to update
     71  * @param autodecline frequency of load decline
     72  */
     73 void
     74 GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load,
     75                                struct GNUNET_TIME_Relative autodecline);
     76 
     77 
     78 /**
     79  * Free a load value.
     80  *
     81  * @param lv value to free
     82  */
     83 #define GNUNET_LOAD_value_free(lv) GNUNET_free (lv)
     84 
     85 
     86 /**
     87  * Get the current load.
     88  *
     89  * @param load load handle
     90  * @return zero for below-average load, otherwise
     91  *         number of std. devs we are above average;
     92  *         100 if the latest updates were so large
     93  *         that we could not do proper calculations
     94  */
     95 double
     96 GNUNET_LOAD_get_load (struct GNUNET_LOAD_Value *load);
     97 
     98 
     99 /**
    100  * Get the average value given to update so far.
    101  *
    102  * @param load load handle
    103  * @return zero if update was never called
    104  */
    105 double
    106 GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load);
    107 
    108 
    109 /**
    110  * Update the current load.
    111  *
    112  * @param load to update
    113  * @param data latest measurement value (for example, delay)
    114  */
    115 void
    116 GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data);
    117 
    118 
    119 #if 0                           /* keep Emacsens' auto-indent happy */
    120 {
    121 #endif
    122 #ifdef __cplusplus
    123 }
    124 #endif
    125 
    126 /* ifndef GNUNET_LOAD_LIB_H */
    127 #endif
    128 
    129 /** @} */  /* end of group */
    130 
    131 /** @} */  /* end of group addition to libgnunetutil */
    132 
    133 /* end of gnunet_load_lib.h */