2 This file is part of GNUnet
3 Copyright (C) 2006, 2009, 2015 Christian Grothoff (and other contributing authors)
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.
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.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file include/gnunet_datacache_plugin.h
23 * @brief API for database backends for the datacache
24 * @author Christian Grothoff
26 #ifndef PLUGIN_DATACACHE_H
27 #define PLUGIN_DATACACHE_H
29 #include "gnunet_datacache_lib.h"
34 #if 0 /* keep Emacsens' auto-indent happy */
41 * Function called by plugins to notify the datacache
42 * about content deletions.
45 * @param key key of the content that was deleted
46 * @param size number of bytes that were made available
49 (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls,
50 const struct GNUNET_HashCode *key,
55 * The datastore service will pass a pointer to a struct
56 * of this type as the first and only argument to the
57 * entry point of each datastore plugin.
59 struct GNUNET_DATACACHE_PluginEnvironment
63 * Configuration to use.
65 const struct GNUNET_CONFIGURATION_Handle *cfg;
68 * Configuration section to use.
73 * Closure to use for callbacks.
78 * Function to call whenever the plugin needs to
79 * discard content that it was asked to store.
81 GNUNET_DATACACHE_DeleteNotifyCallback delete_notify;
84 * How much space are we allowed to use?
86 unsigned long long quota;
92 * @brief struct returned by the initialization function of the plugin
94 struct GNUNET_DATACACHE_PluginFunctions
98 * Closure to pass to all plugin functions.
103 * Store an item in the datastore.
105 * @param cls closure (internal context for the plugin)
106 * @param key key to store the value under
107 * @param size number of bytes in @a data
108 * @param data data to store
109 * @param type type of the value
110 * @param discard_time when to discard the value in any case
111 * @param path_info_len number of entries in @a path_info
112 * @param path_info a path through the network
113 * @return 0 if duplicate, -1 on error, number of bytes used otherwise
115 ssize_t (*put) (void *cls,
116 const struct GNUNET_HashCode *key,
119 enum GNUNET_BLOCK_Type type,
120 struct GNUNET_TIME_Absolute discard_time,
121 unsigned int path_info_len,
122 const struct GNUNET_PeerIdentity *path_info);
125 * Iterate over the results for a particular key
128 * @param cls closure (internal context for the plugin)
129 * @param key key to look for
130 * @param type entries of which type are relevant?
131 * @param iter maybe NULL (to just count)
132 * @param iter_cls closure for @a iter
133 * @return the number of results found
135 unsigned int (*get) (void *cls,
136 const struct GNUNET_HashCode *key,
137 enum GNUNET_BLOCK_Type type,
138 GNUNET_DATACACHE_Iterator iter,
142 * Delete the entry with the lowest expiration value
143 * from the datacache right now.
145 * @param cls closure (internal context for the plugin)
146 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
148 int (*del) (void *cls);
151 * Return a random value from the datastore.
153 * @param cls closure (internal context for the plugin)
154 * @param iter maybe NULL (to just count)
155 * @param iter_cls closure for @a iter
156 * @return the number of results found (zero or one)
158 unsigned int (*get_random) (void *cls,
159 GNUNET_DATACACHE_Iterator iter,
164 * Iterate over the results that are "close" to a particular key in
165 * the datacache. "close" is defined as numerically larger than @a
166 * key (when interpreted as a circular address space), with small
169 * @param cls closure (internal context for the plugin)
170 * @param key area of the keyspace to look into
171 * @param num_results number of results that should be returned to @a iter
172 * @param iter maybe NULL (to just count)
173 * @param iter_cls closure for @a iter
174 * @return the number of results found
176 unsigned int (*get_closest) (void *cls,
177 const struct GNUNET_HashCode *key,
178 unsigned int num_results,
179 GNUNET_DATACACHE_Iterator iter,
185 #if 0 /* keep Emacsens' auto-indent happy */
192 /* end of gnunet_datacache_plugin.h */