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.
17 * @author Christian Grothoff
22 * @defgroup datacache Data Cache library
23 * Simple, transient hash table 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!
32 #ifndef GNUNET_DATACACHE_LIB_H
33 #define GNUNET_DATACACHE_LIB_H
35 #include "gnunet_util_lib.h"
36 #include "gnunet_block_lib.h"
41 #if 0 /* keep Emacsens' auto-indent happy */
48 * Handle to the cache.
50 struct GNUNET_DATACACHE_Handle;
54 * Create a data cache.
56 * @param cfg configuration to use
57 * @param section section in the configuration that contains our options
58 * @return handle to use to access the service
60 struct GNUNET_DATACACHE_Handle *
61 GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
66 * Destroy a data cache (and free associated resources).
68 * @param h handle to the datastore
71 GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
75 * An iterator over a set of items stored in the datacache.
78 * @param key key for the content
79 * @param data_size number of bytes in @a data
80 * @param data content stored
81 * @param type type of the content
82 * @param exp when will the content expire?
83 * @param path_info_len number of entries in @a path_info
84 * @param path_info a path through the network
85 * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
88 (*GNUNET_DATACACHE_Iterator) (void *cls,
89 const struct GNUNET_HashCode *key,
92 enum GNUNET_BLOCK_Type type,
93 struct GNUNET_TIME_Absolute exp,
94 unsigned int path_info_len,
95 const struct GNUNET_PeerIdentity *path_info);
99 * Store an item in the datacache.
101 * @param h handle to the datacache
102 * @param key key to store data under
103 * @param how close is @a key to our pid?
104 * @param data_size number of bytes in @a data
105 * @param data data to store
106 * @param type type of the value
107 * @param discard_time when to discard the value in any case
108 * @param path_info_len number of entries in @a path_info
109 * @param path_info a path through the network
110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate
113 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
114 const struct GNUNET_HashCode *key,
115 uint32_t xor_distance,
118 enum GNUNET_BLOCK_Type type,
119 struct GNUNET_TIME_Absolute discard_time,
120 unsigned int path_info_len,
121 const struct GNUNET_PeerIdentity *path_info);
125 * Iterate over the results for a particular key
128 * @param h handle to the datacache
129 * @param key what to look up
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
136 GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
137 const struct GNUNET_HashCode *key,
138 enum GNUNET_BLOCK_Type type,
139 GNUNET_DATACACHE_Iterator iter,
144 * Obtain a random element from the datacache.
146 * @param h handle to the datacache
147 * @param iter maybe NULL (to just count)
148 * @param iter_cls closure for @a iter
149 * @return the number of results found (zero or 1)
152 GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
153 GNUNET_DATACACHE_Iterator iter,
158 * Iterate over the results that are "close" to a particular key in
159 * the datacache. "close" is defined as numerically larger than @a
160 * key (when interpreted as a circular address space), with small
163 * @param h handle to the datacache
164 * @param key area of the keyspace to look into
165 * @param num_results number of results that should be returned to @a iter
166 * @param iter maybe NULL (to just count)
167 * @param iter_cls closure for @a iter
168 * @return the number of results found
171 GNUNET_DATACACHE_get_closest (struct GNUNET_DATACACHE_Handle *h,
172 const struct GNUNET_HashCode *key,
173 unsigned int num_results,
174 GNUNET_DATACACHE_Iterator iter,
178 #if 0 /* keep Emacsens' auto-indent happy */
187 /** @} */ /* end of group */