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_lib.h
23 * @brief datacache is a simple, transient hash table
24 * of bounded size with content expiration.
25 * In contrast to the sqstore there is
26 * no prioritization, deletion or iteration.
27 * All of the data is discarded when the peer shuts down!
28 * @author Christian Grothoff
31 #ifndef GNUNET_DATACACHE_LIB_H
32 #define GNUNET_DATACACHE_LIB_H
34 #include "gnunet_util_lib.h"
35 #include "gnunet_block_lib.h"
40 #if 0 /* keep Emacsens' auto-indent happy */
47 * Handle to the cache.
49 struct GNUNET_DATACACHE_Handle;
53 * Create a data cache.
55 * @param cfg configuration to use
56 * @param section section in the configuration that contains our options
57 * @return handle to use to access the service
59 struct GNUNET_DATACACHE_Handle *
60 GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
65 * Destroy a data cache (and free associated resources).
67 * @param h handle to the datastore
70 GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
74 * An iterator over a set of items stored in the datacache.
77 * @param key key for the content
78 * @param data_size number of bytes in @a data
79 * @param data content stored
80 * @param type type of the content
81 * @param exp when will the content expire?
82 * @param path_info_len number of entries in @a path_info
83 * @param path_info a path through the network
84 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
87 (*GNUNET_DATACACHE_Iterator) (void *cls,
88 const struct GNUNET_HashCode *key,
91 enum GNUNET_BLOCK_Type type,
92 struct GNUNET_TIME_Absolute exp,
93 unsigned int path_info_len,
94 const struct GNUNET_PeerIdentity *path_info);
98 * Store an item in the datacache.
100 * @param h handle to the datacache
101 * @param key key to store data under
102 * @param data_size number of bytes in @a data
103 * @param data data to store
104 * @param type type of the value
105 * @param discard_time when to discard the value in any case
106 * @param path_info_len number of entries in @a path_info
107 * @param path_info a path through the network
108 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate
111 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
112 const struct GNUNET_HashCode *key,
115 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);
122 * Iterate over the results for a particular key
125 * @param h handle to the datacache
126 * @param key what to look up
127 * @param type entries of which type are relevant?
128 * @param iter maybe NULL (to just count)
129 * @param iter_cls closure for @a iter
130 * @return the number of results found
133 GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
134 const struct GNUNET_HashCode *key,
135 enum GNUNET_BLOCK_Type type,
136 GNUNET_DATACACHE_Iterator iter,
141 * Obtain a random element from the datacache.
143 * @param h handle to the datacache
144 * @param iter maybe NULL (to just count)
145 * @param iter_cls closure for @a iter
146 * @return the number of results found (zero or 1)
149 GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
150 GNUNET_DATACACHE_Iterator iter,
155 * Iterate over the results that are "close" to a particular key in
156 * the datacache. "close" is defined as numerically larger than @a
157 * key (when interpreted as a circular address space), with small
160 * @param h handle to the datacache
161 * @param key area of the keyspace to look into
162 * @param num_results number of results that should be returned to @a iter
163 * @param iter maybe NULL (to just count)
164 * @param iter_cls closure for @a iter
165 * @return the number of results found
168 GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
169 const struct GNUNET_HashCode *key,
170 unsigned int num_results,
171 GNUNET_DATACACHE_Iterator iter,
175 #if 0 /* keep Emacsens' auto-indent happy */
182 /* end of gnunet_datacache_lib.h */