client_manager: add API for async operations
[oweals/gnunet.git] / src / include / gnunet_datacache_lib.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2006, 2009, 2015 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
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
29  */
30
31 #ifndef GNUNET_DATACACHE_LIB_H
32 #define GNUNET_DATACACHE_LIB_H
33
34 #include "gnunet_util_lib.h"
35 #include "gnunet_block_lib.h"
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #if 0                           /* keep Emacsens' auto-indent happy */
41 }
42 #endif
43 #endif
44
45
46 /**
47  * Handle to the cache.
48  */
49 struct GNUNET_DATACACHE_Handle;
50
51
52 /**
53  * Create a data cache.
54  *
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
58  */
59 struct GNUNET_DATACACHE_Handle *
60 GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
61                          const char *section);
62
63
64 /**
65  * Destroy a data cache (and free associated resources).
66  *
67  * @param h handle to the datastore
68  */
69 void
70 GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
71
72
73 /**
74  * An iterator over a set of items stored in the datacache.
75  *
76  * @param cls closure
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
85  */
86 typedef int
87 (*GNUNET_DATACACHE_Iterator) (void *cls,
88                               const struct GNUNET_HashCode *key,
89                               size_t data_size,
90                               const char *data,
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);
95
96
97 /**
98  * Store an item in the datacache.
99  *
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
109  */
110 int
111 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
112                       const struct GNUNET_HashCode *key,
113                       size_t data_size,
114                       const char *data,
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);
119
120
121 /**
122  * Iterate over the results for a particular key
123  * in the datacache.
124  *
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
131  */
132 unsigned int
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,
137                       void *iter_cls);
138
139
140 /**
141  * Obtain a random element from the datacache.
142  *
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)
147  */
148 unsigned int
149 GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h,
150                              GNUNET_DATACACHE_Iterator iter,
151                              void *iter_cls);
152
153
154 /**
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
158  * distance.
159  *
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
166  */
167 unsigned int
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,
172                               void *iter_cls);
173
174
175 #if 0                           /* keep Emacsens' auto-indent happy */
176 {
177 #endif
178 #ifdef __cplusplus
179 }
180 #endif
181
182 /* end of gnunet_datacache_lib.h */
183 #endif