2 This file is part of GNUnet
3 Copyright (C) 2006, 2009, 2015 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
25 * API for database backends for the datacache
27 * @defgroup datacache-plugin Data Cache plugin API
28 * API for database backends for the datacache
31 #ifndef PLUGIN_DATACACHE_H
32 #define PLUGIN_DATACACHE_H
34 #include "gnunet_datacache_lib.h"
39 #if 0 /* keep Emacsens' auto-indent happy */
46 * Function called by plugins to notify the datacache
47 * about content deletions.
50 * @param key key of the content that was deleted
51 * @param size number of bytes that were made available
54 (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls,
55 const struct GNUNET_HashCode *key,
60 * The datastore service will pass a pointer to a struct
61 * of this type as the first and only argument to the
62 * entry point of each datastore plugin.
64 struct GNUNET_DATACACHE_PluginEnvironment
68 * Configuration to use.
70 const struct GNUNET_CONFIGURATION_Handle *cfg;
73 * Configuration section to use.
78 * Closure to use for callbacks.
83 * Function to call whenever the plugin needs to
84 * discard content that it was asked to store.
86 GNUNET_DATACACHE_DeleteNotifyCallback delete_notify;
89 * How much space are we allowed to use?
91 unsigned long long quota;
97 * @brief struct returned by the initialization function of the plugin
99 struct GNUNET_DATACACHE_PluginFunctions
103 * Closure to pass to all plugin functions.
108 * Store an item in the datastore.
110 * @param cls closure (internal context for the plugin)
111 * @param key key to store the value under
112 * @param xor_distance how close is @a key to our PID?
113 * @param size number of bytes in @a data
114 * @param data data to store
115 * @param type type of the value
116 * @param discard_time when to discard the value in any case
117 * @param path_info_len number of entries in @a path_info
118 * @param path_info a path through the network
119 * @return 0 if duplicate, -1 on error, number of bytes used otherwise
121 ssize_t (*put) (void *cls,
122 const struct GNUNET_HashCode *key,
123 uint32_t xor_distance,
126 enum GNUNET_BLOCK_Type type,
127 struct GNUNET_TIME_Absolute discard_time,
128 unsigned int path_info_len,
129 const struct GNUNET_PeerIdentity *path_info);
132 * Iterate over the results for a particular key
135 * @param cls closure (internal context for the plugin)
136 * @param key key to look for
137 * @param type entries of which type are relevant?
138 * @param iter maybe NULL (to just count)
139 * @param iter_cls closure for @a iter
140 * @return the number of results found
142 unsigned int (*get) (void *cls,
143 const struct GNUNET_HashCode *key,
144 enum GNUNET_BLOCK_Type type,
145 GNUNET_DATACACHE_Iterator iter,
149 * Delete the entry with the lowest expiration value
150 * from the datacache right now.
152 * @param cls closure (internal context for the plugin)
153 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
155 int (*del) (void *cls);
158 * Return a random value from the datastore.
160 * @param cls closure (internal context for the plugin)
161 * @param iter maybe NULL (to just count)
162 * @param iter_cls closure for @a iter
163 * @return the number of results found (zero or one)
165 unsigned int (*get_random) (void *cls,
166 GNUNET_DATACACHE_Iterator iter,
171 * Iterate over the results that are "close" to a particular key in
172 * the datacache. "close" is defined as numerically larger than @a
173 * key (when interpreted as a circular address space), with small
176 * @param cls closure (internal context for the plugin)
177 * @param key area of the keyspace to look into
178 * @param num_results number of results that should be returned to @a iter
179 * @param iter maybe NULL (to just count)
180 * @param iter_cls closure for @a iter
181 * @return the number of results found
183 unsigned int (*get_closest) (void *cls,
184 const struct GNUNET_HashCode *key,
185 unsigned int num_results,
186 GNUNET_DATACACHE_Iterator iter,
192 #if 0 /* keep Emacsens' auto-indent happy */
201 /** @} */ /* end of group */