adding number of preferences to allow iterating over preferences
[oweals/gnunet.git] / src / include / gnunet_datacache_lib.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2006, 2009 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 size number of bytes in 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 '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 (*GNUNET_DATACACHE_Iterator) (void *cls,
87                                           const struct GNUNET_HashCode *key,
88                                           size_t size, const char *data,
89                                           enum GNUNET_BLOCK_Type type,
90                                           struct GNUNET_TIME_Absolute exp,
91                                           unsigned int path_info_len,
92                                           const struct GNUNET_PeerIdentity *path_info);
93
94
95 /**
96  * Store an item in the datacache.
97  *
98  * @param h handle to the datacache
99  * @param key key to store data under
100  * @param size number of bytes in data
101  * @param data data to store
102  * @param type type of the value
103  * @param discard_time when to discard the value in any case
104  * @param path_info_len number of entries in 'path_info'
105  * @param path_info a path through the network
106  * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if duplicate
107  */
108 int
109 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
110                       const struct GNUNET_HashCode * key, size_t size,
111                       const char *data, enum GNUNET_BLOCK_Type type,
112                       struct GNUNET_TIME_Absolute discard_time,
113                       unsigned int path_info_len,
114                       const struct GNUNET_PeerIdentity *path_info);
115
116
117 /**
118  * Iterate over the results for a particular key
119  * in the datacache.
120  *
121  * @param h handle to the datacache
122  * @param key what to look up
123  * @param type entries of which type are relevant?
124  * @param iter maybe NULL (to just count)
125  * @param iter_cls closure for iter
126  * @return the number of results found
127  */
128 unsigned int
129 GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
130                       const struct GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type,
131                       GNUNET_DATACACHE_Iterator iter, void *iter_cls);
132
133
134 #if 0                           /* keep Emacsens' auto-indent happy */
135 {
136 #endif
137 #ifdef __cplusplus
138 }
139 #endif
140
141 /* end of gnunet_datacache_lib.h */
142 #endif