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
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 * @author Christian Grothoff
27 * @defgroup datacache Data Cache library
28 * Simple, transient hash table of bounded size with content expiration.
30 * In contrast to the sqstore there is
31 * no prioritization, deletion or iteration.
32 * All of the data is discarded when the peer shuts down!
37 #ifndef GNUNET_DATACACHE_LIB_H
38 #define GNUNET_DATACACHE_LIB_H
40 #include "gnunet_util_lib.h"
41 #include "gnunet_block_lib.h"
46 #if 0 /* keep Emacsens' auto-indent happy */
53 * Handle to the cache.
55 struct GNUNET_DATACACHE_Handle;
59 * Create a data cache.
61 * @param cfg configuration to use
62 * @param section section in the configuration that contains our options
63 * @return handle to use to access the service
65 struct GNUNET_DATACACHE_Handle *
66 GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
71 * Destroy a data cache (and free associated resources).
73 * @param h handle to the datastore
76 GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
80 * An iterator over a set of items stored in the datacache.
83 * @param key key for the content
84 * @param data_size number of bytes in @a data
85 * @param data content stored
86 * @param type type of the content
87 * @param exp when will the content expire?
88 * @param path_info_len number of entries in @a path_info
89 * @param path_info a path through the network
90 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
93 (*GNUNET_DATACACHE_Iterator) (void *cls,
94 const struct GNUNET_HashCode *key,
97 enum GNUNET_BLOCK_Type type,
98 struct GNUNET_TIME_Absolute exp,
99 unsigned int path_info_len,
100 const struct GNUNET_PeerIdentity *path_info);
104 * Store an item in the datacache.
106 * @param h handle to the datacache
107 * @param key key to store data under
108 * @param data_size number of bytes in @a data
109 * @param data data to store
110 * @param type type of the value
111 * @param discard_time when to discard the value in any case
112 * @param path_info_len number of entries in @a path_info
113 * @param path_info a path through the network
114 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate
117 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
118 const struct GNUNET_HashCode *key,
121 enum GNUNET_BLOCK_Type type,
122 struct GNUNET_TIME_Absolute discard_time,
123 unsigned int path_info_len,
124 const struct GNUNET_PeerIdentity *path_info);
128 * Iterate over the results for a particular key
131 * @param h handle to the datacache
132 * @param key what to look up
133 * @param type entries of which type are relevant?
134 * @param iter maybe NULL (to just count)
135 * @param iter_cls closure for @a iter
136 * @return the number of results found
139 GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
140 const struct GNUNET_HashCode *key,
141 enum GNUNET_BLOCK_Type type,
142 GNUNET_DATACACHE_Iterator iter,
147 * Obtain a random element from the datacache.
149 * @param h handle to the datacache
150 * @param iter maybe NULL (to just count)
151 * @param iter_cls closure for @a iter
152 * @return the number of results found (zero or 1)
155 GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
156 GNUNET_DATACACHE_Iterator iter,
161 * Iterate over the results that are "close" to a particular key in
162 * the datacache. "close" is defined as numerically larger than @a
163 * key (when interpreted as a circular address space), with small
166 * @param h handle to the datacache
167 * @param key area of the keyspace to look into
168 * @param num_results number of results that should be returned to @a iter
169 * @param iter maybe NULL (to just count)
170 * @param iter_cls closure for @a iter
171 * @return the number of results found
174 GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
175 const struct GNUNET_HashCode *key,
176 unsigned int num_results,
177 GNUNET_DATACACHE_Iterator iter,
181 #if 0 /* keep Emacsens' auto-indent happy */
190 /** @} */ /* end of group */