gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

gnunet_datastore_plugin.h (10782B)


      1 /*
      2      This file is part of GNUnet
      3      Copyright (C) 2009, 2011 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 fs_l2  File sharing and support services/libraries
     23  * @{
     24  *
     25  * @author Christian Grothoff
     26  *
     27  * @file
     28  * API for the database backend plugins.
     29  *
     30  * @defgroup datastore-plugin  Data Store service plugin API
     31  * API for the database backend plugins.
     32  * @{
     33  */
     34 #ifndef PLUGIN_DATASTORE_H
     35 #define PLUGIN_DATASTORE_H
     36 
     37 
     38 #include "gnunet_block_lib.h"
     39 #include "gnunet_configuration_lib.h"
     40 #include "gnunet_datastore_service.h"
     41 #include "gnunet_statistics_service.h"
     42 #include "gnunet_scheduler_lib.h"
     43 
     44 
     45 /**
     46  * How many bytes of overhead will we assume per entry
     47  * in any DB (for reservations)?
     48  */
     49 #define GNUNET_DATASTORE_ENTRY_OVERHEAD 256
     50 
     51 
     52 /**
     53  * Function invoked to notify service of disk utilization
     54  * changes.
     55  *
     56  * @param cls closure
     57  * @param delta change in disk utilization,
     58  *        0 for "reset to empty"
     59  */
     60 typedef void
     61 (*GNUNET_DATASTORE_DiskUtilizationChange) (void *cls,
     62                                            int delta);
     63 
     64 
     65 /**
     66  * The datastore service will pass a pointer to a struct
     67  * of this type as the first and only argument to the
     68  * entry point of each datastore plugin.
     69  */
     70 struct GNUNET_DATASTORE_PluginEnvironment
     71 {
     72   /**
     73    * Configuration to use.
     74    */
     75   const struct GNUNET_CONFIGURATION_Handle *cfg;
     76 
     77   /**
     78    * Function to call on disk utilization change.
     79    */
     80   GNUNET_DATASTORE_DiskUtilizationChange duc;
     81 
     82   /**
     83    * Closure.
     84    */
     85   void *cls;
     86 };
     87 
     88 
     89 /**
     90  * An processor over a set of items stored in the datastore.
     91  *
     92  * @param cls closure
     93  * @param key key for the content
     94  * @param size number of bytes in data
     95  * @param data content stored
     96  * @param type type of the content
     97  * @param priority priority of the content
     98  * @param anonymity anonymity-level for the content
     99  * @param replication replication-level for the content
    100  * @param expiration expiration time for the content
    101  * @param uid unique identifier for the datum
    102  * @return #GNUNET_OK to keep the item
    103  *         #GNUNET_NO to delete the item
    104  */
    105 typedef enum GNUNET_GenericReturnValue
    106 (*PluginDatumProcessor)(void *cls,
    107                         const struct GNUNET_HashCode *key,
    108                         uint32_t size,
    109                         const void *data,
    110                         enum GNUNET_BLOCK_Type type,
    111                         uint32_t priority,
    112                         uint32_t anonymity,
    113                         uint32_t replication,
    114                         struct GNUNET_TIME_Absolute expiration,
    115                         uint64_t uid);
    116 
    117 
    118 /**
    119  * Get an estimate of how much space the database is
    120  * currently using.
    121  *
    122  * NB: estimate is an output parameter because emscripten cannot handle
    123  * returning 64-bit integers from dynamically loaded modules.
    124  *
    125  * @param cls closure
    126  * @param estimate location to store estimate
    127  * @return number of bytes used on disk
    128  */
    129 typedef void
    130 (*PluginEstimateSize) (void *cls,
    131                        unsigned long long *estimate);
    132 
    133 
    134 /**
    135  * Put continuation.
    136  *
    137  * @param cls closure
    138  * @param key key for the item stored
    139  * @param size size of the item stored
    140  * @param status #GNUNET_OK if inserted, #GNUNET_NO if updated,
    141  *        or #GNUNET_SYSERROR if error
    142  * @param msg error message on error
    143  */
    144 typedef void
    145 (*PluginPutCont) (void *cls,
    146                   const struct GNUNET_HashCode *key,
    147                   uint32_t size,
    148                   int status,
    149                   const char *msg);
    150 
    151 
    152 /**
    153  * Store an item in the datastore.  If the item is already present,
    154  * the priorities and replication levels are summed up and the higher
    155  * expiration time and lower anonymity level is used.
    156  *
    157  * @param cls closure
    158  * @param key key for the item
    159  * @param absent true if the key was not found in the bloom filter
    160  * @param size number of bytes in @a data
    161  * @param data content stored
    162  * @param type type of the content
    163  * @param priority priority of the content
    164  * @param anonymity anonymity-level for the content
    165  * @param replication replication-level for the content
    166  * @param expiration expiration time for the content
    167  * @param cont continuation called with success or failure status
    168  * @param cont_cls continuation closure for @a cont
    169  */
    170 typedef void
    171 (*PluginPut) (void *cls,
    172               const struct GNUNET_HashCode *key,
    173               bool absent,
    174               uint32_t size,
    175               const void *data,
    176               enum GNUNET_BLOCK_Type type,
    177               uint32_t priority,
    178               uint32_t anonymity,
    179               uint32_t replication,
    180               struct GNUNET_TIME_Absolute expiration,
    181               PluginPutCont cont,
    182               void *cont_cls);
    183 
    184 
    185 /**
    186  * An processor over a set of keys stored in the datastore.
    187  *
    188  * @param cls closure
    189  * @param key key in the data store, if NULL iteration is finished
    190  * @param count how many values are stored under this key in the datastore
    191  */
    192 typedef void
    193 (*PluginKeyProcessor) (void *cls,
    194                        const struct GNUNET_HashCode *key,
    195                        unsigned int count);
    196 
    197 
    198 /**
    199  * Get all of the keys in the datastore.
    200  *
    201  * @param cls closure
    202  * @param proc function to call on each key
    203  * @param proc_cls closure for @a proc
    204  */
    205 typedef void
    206 (*PluginGetKeys) (void *cls,
    207                   PluginKeyProcessor proc,
    208                   void *proc_cls);
    209 
    210 
    211 /**
    212  * Get one of the results for a particular key in the datastore.
    213  *
    214  * @param cls closure
    215  * @param next_uid return the result with lowest uid >= next_uid
    216  * @param random if true, return a random result instead of using next_uid
    217  * @param key maybe NULL (to match all entries)
    218  * @param type entries of which type are relevant?
    219  *     Use 0 for any type.
    220  * @param proc function to call on the matching value;
    221  *        will be called with NULL if nothing matches
    222  * @param proc_cls closure for @a proc
    223  */
    224 typedef void
    225 (*PluginGetKey) (void *cls,
    226                  uint64_t next_uid,
    227                  bool random,
    228                  const struct GNUNET_HashCode *key,
    229                  enum GNUNET_BLOCK_Type type,
    230                  PluginDatumProcessor proc,
    231                  void *proc_cls);
    232 
    233 
    234 /**
    235  * Remove continuation.
    236  *
    237  * @param cls closure
    238  * @param key key for the content removed
    239  * @param size number of bytes removed
    240  * @param status #GNUNET_OK if removed, #GNUNET_NO if not found,
    241  *        or #GNUNET_SYSERROR if error
    242  * @param msg error message on error
    243  */
    244 typedef void
    245 (*PluginRemoveCont) (void *cls,
    246                      const struct GNUNET_HashCode *key,
    247                      uint32_t size,
    248                      int status,
    249                      const char *msg);
    250 
    251 
    252 /**
    253  * Remove a particular key in the datastore.
    254  *
    255  * @param cls closure
    256  * @param key key for the content
    257  * @param size number of bytes in data
    258  * @param data content stored
    259  * @param cont continuation called with success or failure status
    260  * @param cont_cls continuation closure for @a cont
    261  */
    262 typedef void
    263 (*PluginRemoveKey) (void *cls,
    264                     const struct GNUNET_HashCode *key,
    265                     uint32_t size,
    266                     const void *data,
    267                     PluginRemoveCont cont,
    268                     void *cont_cls);
    269 
    270 
    271 /**
    272  * Get a random item (additional constraints may apply depending on
    273  * the specific implementation).  Calls @a proc with all values ZERO or
    274  * NULL if no item applies, otherwise @a proc is called once and only
    275  * once with an item.
    276  *
    277  * @param cls closure
    278  * @param proc function to call the value (once only).
    279  * @param proc_cls closure for @a proc
    280  */
    281 typedef void
    282 (*PluginGetRandom) (void *cls,
    283                     PluginDatumProcessor proc,
    284                     void *proc_cls);
    285 
    286 
    287 /**
    288  * Select a single item from the datastore (among those applicable).
    289  *
    290  * @param cls closure
    291  * @param next_uid return the result with lowest uid >= next_uid
    292  * @param type entries of which type should be considered?
    293  *        Must not be zero (ANY).
    294  * @param proc function to call on the matching value;
    295  *        will be called with NULL if no value matches
    296  * @param proc_cls closure for @a proc
    297  */
    298 typedef void
    299 (*PluginGetType) (void *cls,
    300                   uint64_t next_uid,
    301                   enum GNUNET_BLOCK_Type type,
    302                   PluginDatumProcessor proc,
    303                   void *proc_cls);
    304 
    305 
    306 /**
    307  * Drop database.
    308  *
    309  * @param cls closure
    310  */
    311 typedef void
    312 (*PluginDrop) (void *cls);
    313 
    314 
    315 /**
    316  * Each plugin is required to return a pointer to a struct of this
    317  * type as the return value from its entry point.
    318  */
    319 struct GNUNET_DATASTORE_PluginFunctions
    320 {
    321   /**
    322    * Closure to use for all of the following callbacks
    323    * (except "next_request").
    324    */
    325   void *cls;
    326 
    327   /**
    328    * Calculate the current on-disk size of the SQ store.  Estimates
    329    * are fine, if that's the only thing available.
    330    */
    331   PluginEstimateSize estimate_size;
    332 
    333   /**
    334    * Function to store an item in the datastore.
    335    */
    336   PluginPut put;
    337 
    338   /**
    339    * Get a particular datum matching a given hash from the datastore.
    340    */
    341   PluginGetKey get_key;
    342 
    343   /**
    344    * Get datum (of the specified type) with anonymity level zero.
    345    */
    346   PluginGetType get_zero_anonymity;
    347 
    348   /**
    349    * Function to get a random item with high replication score from
    350    * the database, lowering the item's replication score.  Returns a
    351    * single random item from those with the highest replication
    352    * counters.  The item's replication counter is decremented by one
    353    * IF it was positive before.
    354    */
    355   PluginGetRandom get_replication;
    356 
    357   /**
    358    * Function to get a random expired item or, if none are expired,
    359    * either the oldest entry or one with a low priority (depending
    360    * on what was efficiently implementable).
    361    */
    362   PluginGetRandom get_expiration;
    363 
    364   /**
    365    * Delete the database.  The next operation is
    366    * guaranteed to be unloading of the module.
    367    */
    368   PluginDrop drop;
    369 
    370   /**
    371    * Iterate over all keys in the database.
    372    */
    373   PluginGetKeys get_keys;
    374 
    375   /**
    376    * Function to remove an item from the database.
    377    */
    378   PluginRemoveKey remove_key;
    379 };
    380 
    381 #endif
    382 
    383 /** @} */  /* end of group */
    384 
    385 /** @} */ /* end of group addition */