2 This file is part of GNUnet
3 (C) 2006, 2009 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 2, 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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 sched scheduler to use
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 (struct GNUNET_SCHEDULER_Handle *sched,
62 const struct GNUNET_CONFIGURATION_Handle *cfg,
67 * Destroy a data cache (and free associated resources).
69 * @param h handle to the datastore
71 void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h);
75 * An iterator over a set of items stored in the datacache.
78 * @param exp when will the content expire?
79 * @param key key for the content
80 * @param size number of bytes in data
81 * @param data content stored
82 * @param type type of the content
83 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
85 typedef int (*GNUNET_DATACACHE_Iterator) (void *cls,
86 struct GNUNET_TIME_Absolute exp,
87 const GNUNET_HashCode * key,
90 enum GNUNET_BLOCK_Type type);
94 * Store an item in the datacache.
96 * @param h handle to the datacache
97 * @param key key to store data under
98 * @param size number of bytes in data
99 * @param data data to store
100 * @param type type of the value
101 * @param discard_time when to discard the value in any case
102 * @return GNUNET_OK on success, GNUNET_SYSERR on error (full, etc.)
105 GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
106 const GNUNET_HashCode * key,
109 enum GNUNET_BLOCK_Type type,
110 struct GNUNET_TIME_Absolute discard_time);
114 * Iterate over the results for a particular key
117 * @param h handle to the datacache
118 * @param key what to look up
119 * @param type entries of which type are relevant?
120 * @param iter maybe NULL (to just count)
121 * @param iter_cls closure for iter
122 * @return the number of results found
125 GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
126 const GNUNET_HashCode * key,
127 enum GNUNET_BLOCK_Type type,
128 GNUNET_DATACACHE_Iterator iter,
132 #if 0 /* keep Emacsens' auto-indent happy */
139 /* end of gnunet_datacache_lib.h */