- use tunnel encryption state to select decryption key
[oweals/gnunet.git] / src / include / gnunet_datacache_plugin.h
1 /*
2      This file is part of GNUnet
3      (C) 2006, 2009 Christian Grothoff (and other contributing authors)
4
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 3, or (at your
8      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      General Public License for more details.
14
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.
19 */
20
21 /**
22  * @file include/gnunet_datacache_plugin.h
23  * @brief API for database backends for the datacache
24  * @author Christian Grothoff
25  */
26 #ifndef PLUGIN_DATACACHE_H
27 #define PLUGIN_DATACACHE_H
28
29 #include "gnunet_datacache_lib.h"
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #if 0                           /* keep Emacsens' auto-indent happy */
35 }
36 #endif
37 #endif
38
39
40 /**
41  * Function called by plugins to notify the datacache
42  * about content deletions.
43  *
44  * @param cls closure
45  * @param key key of the content that was deleted
46  * @param size number of bytes that were made available
47  */
48 typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls,
49                                                        const struct GNUNET_HashCode *
50                                                        key, size_t size);
51
52
53 /**
54  * The datastore service will pass a pointer to a struct
55  * of this type as the first and only argument to the
56  * entry point of each datastore plugin.
57  */
58 struct GNUNET_DATACACHE_PluginEnvironment
59 {
60
61
62   /**
63    * Configuration to use.
64    */
65   const struct GNUNET_CONFIGURATION_Handle *cfg;
66
67   /**
68    * Configuration section to use.
69    */
70   const char *section;
71
72   /**
73    * Closure to use for callbacks.
74    */
75   void *cls;
76
77   /**
78    * Function to call whenever the plugin needs to
79    * discard content that it was asked to store.
80    */
81   GNUNET_DATACACHE_DeleteNotifyCallback delete_notify;
82
83   /**
84    * How much space are we allowed to use?
85    */
86   unsigned long long quota;
87
88 };
89
90
91 /**
92  * @brief struct returned by the initialization function of the plugin
93  */
94 struct GNUNET_DATACACHE_PluginFunctions
95 {
96
97   /**
98    * Closure to pass to all plugin functions.
99    */
100   void *cls;
101
102   /**
103    * Store an item in the datastore.
104    *
105    * @param cls closure (internal context for the plugin)
106    * @param size number of bytes in data
107    * @param data data to store
108    * @param type type of the value
109    * @param discard_time when to discard the value in any case
110    * @param path_info_len number of entries in 'path_info'
111    * @param path_info a path through the network
112    * @return 0 if duplicate, -1 on error, number of bytes used otherwise
113    */
114   ssize_t (*put) (void *cls, const struct GNUNET_HashCode * key, size_t size,
115                   const char *data, enum GNUNET_BLOCK_Type type,
116                   struct GNUNET_TIME_Absolute discard_time,
117                   unsigned int path_info_len,
118                   const struct GNUNET_PeerIdentity *path_info);
119
120
121   /**
122    * Iterate over the results for a particular key
123    * in the datastore.
124    *
125    * @param cls closure (internal context for the plugin)
126    * @param key
127    * @param type entries of which type are relevant?
128    * @param iter maybe NULL (to just count)
129    * @param iter_cls closure for iter
130    * @return the number of results found
131    */
132   unsigned int (*get) (void *cls, const struct GNUNET_HashCode * key,
133                        enum GNUNET_BLOCK_Type type,
134                        GNUNET_DATACACHE_Iterator iter, void *iter_cls);
135
136
137   /**
138    * Delete the entry with the lowest expiration value
139    * from the datacache right now.
140    *
141    * @param cls closure (internal context for the plugin)
142    * @return GNUNET_OK on success, GNUNET_SYSERR on error
143    */
144   int (*del) (void *cls);
145
146
147 };
148
149
150 #if 0                           /* keep Emacsens' auto-indent happy */
151 {
152 #endif
153 #ifdef __cplusplus
154 }
155 #endif
156
157 /* end of gnunet_datacache_plugin.h */
158 #endif