e23833267d642f2cdf521521f7991d066edcd328
[oweals/gnunet.git] / src / include / gnunet_peerstore_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2012, 2013 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU 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
16 /**
17  * @author Omar Tarabai
18  *
19  * @file
20  * Plugin API for the peerstore database backend
21  *
22  * @defgroup peerstore-plugin  Peer Store service plugin API
23  * Plugin API for the peerstore database backend
24  * @{
25  */
26 #ifndef GNUNET_PEERSTORE_PLUGIN_H
27 #define GNUNET_PEERSTORE_PLUGIN_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_peerstore_service.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /**
42  * @brief struct returned by the initialization function of the plugin
43  */
44 struct GNUNET_PEERSTORE_PluginFunctions
45 {
46
47   /**
48    * Closure to pass to all plugin functions.
49    */
50   void *cls;
51
52   /**
53    * Store a record in the peerstore.
54    * Key is the combination of sub system and peer identity.
55    * One key can store multiple values.
56    *
57    * @param cls closure (internal context for the plugin)
58    * @param sub_system name of the GNUnet sub system responsible
59    * @param peer peer identity
60    * @param value value to be stored
61    * @param size size of value to be stored
62    * @param expiry absolute time after which the record is (possibly) deleted
63    * @param options options related to the store operation
64    * @param cont continuation called when record is stored
65    * @param cont_cls continuation closure
66    * @return #GNUNET_OK on success, else #GNUNET_SYSERR and cont is not called
67    */
68   int
69   (*store_record) (void *cls,
70                    const char *sub_system,
71                    const struct GNUNET_PeerIdentity *peer,
72                    const char *key,
73                    const void *value,
74                    size_t size,
75                    struct GNUNET_TIME_Absolute expiry,
76                    enum GNUNET_PEERSTORE_StoreOption options,
77                    GNUNET_PEERSTORE_Continuation cont,
78                    void *cont_cls);
79
80   /**
81    * Iterate over the records given an optional peer id
82    * and/or key.
83    *
84    * @param cls closure (internal context for the plugin)
85    * @param sub_system name of sub system
86    * @param peer Peer identity (can be NULL)
87    * @param key entry key string (can be NULL)
88    * @param iter function to call asynchronously with the results, terminated
89    * by a NULL result
90    * @param iter_cls closure for @a iter
91    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and iter is not
92    * called
93    */
94   int
95   (*iterate_records) (void *cls,
96                       const char *sub_system,
97                       const struct GNUNET_PeerIdentity *peer,
98                       const char *key,
99                       GNUNET_PEERSTORE_Processor iter,
100                       void *iter_cls);
101
102   /**
103    * Delete expired records (expiry < now)
104    *
105    * @param cls closure (internal context for the plugin)
106    * @param now time to use as reference
107    * @param cont continuation called with the number of records expired
108    * @param cont_cls continuation closure
109    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and cont is not
110    * called
111    */
112   int
113   (*expire_records) (void *cls,
114                      struct GNUNET_TIME_Absolute now,
115                      GNUNET_PEERSTORE_Continuation cont,
116                      void *cont_cls);
117
118 };
119
120
121 #if 0                           /* keep Emacsens' auto-indent happy */
122 {
123 #endif
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif
129
130 /** @} */  /* end of group */