2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011 GNUnet e.V.
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 dht/gnunet-service-dht_datacache.h
23 * @brief GNUnet DHT service's datacache integration
24 * @author Christian Grothoff
25 * @author Nathan Evans
27 #ifndef GNUNET_SERVICE_DHT_DATACACHE_H
28 #define GNUNET_SERVICE_DHT_DATACACHE_H
30 #include "gnunet_util_lib.h"
31 #include "gnunet_block_lib.h"
32 #include "gnunet_dht_service.h"
35 * Handle a datum we've received from another peer. Cache if
38 * @param expiration when will the reply expire
39 * @param key the query this reply is for
40 * @param put_path_length number of peers in 'put_path'
41 * @param put_path path the reply took on put
42 * @param type type of the reply
43 * @param data_size number of bytes in 'data'
44 * @param data application payload data
47 GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
48 const struct GNUNET_HashCode *key,
49 unsigned int put_path_length,
50 const struct GNUNET_PeerIdentity *put_path,
51 enum GNUNET_BLOCK_Type type,
57 * Handle a result for a GET operation.
60 * @param type type of the block
61 * @param expiration_time when does the content expire
62 * @param key key for the content
63 * @param put_path_length number of entries in @a put_path
64 * @param put_path peers the original PUT traversed (if tracked)
65 * @param get_path_length number of entries in @a get_path
66 * @param get_path peers this reply has traversed so far (if tracked)
67 * @param data payload of the reply
68 * @param data_size number of bytes in @a data
71 (*GDS_DATACACHE_GetCallback)(void *cls,
72 enum GNUNET_BLOCK_Type type,
73 struct GNUNET_TIME_Absolute expiration_time,
74 const struct GNUNET_HashCode *key,
75 unsigned int put_path_length,
76 const struct GNUNET_PeerIdentity *put_path,
77 unsigned int get_path_length,
78 const struct GNUNET_PeerIdentity *get_path,
84 * Handle a GET request we've received from another peer.
86 * @param key the query
87 * @param type requested data type
88 * @param xquery extended query
89 * @param xquery_size number of bytes in xquery
90 * @param reply_bf where the reply bf is (to be) stored, possibly updated!, can be NULL
91 * @param reply_bf_mutator mutation value for reply_bf
92 * @param gc function to call on the results
93 * @param gc_cls closure for @a gc
94 * @return evaluation result for the local replies
96 enum GNUNET_BLOCK_EvaluationResult
97 GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
98 enum GNUNET_BLOCK_Type type,
101 struct GNUNET_CONTAINER_BloomFilter **reply_bf,
102 uint32_t reply_bf_mutator,
103 GDS_DATACACHE_GetCallback gc,
108 * Obtain a random key from the datacache.
109 * Used by Whanau for load-balancing.
111 * @param[out] key where to store the key of a random element,
112 * randomized by PRNG if datacache is empty
113 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty
116 GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key);
120 * Send the get result to requesting client.
123 * @param options routing options (from GET request)
124 * @param key key of the requested data.
125 * @param type block type
126 * @param put_path_length number of peers in @a put_path
127 * @param put_path path taken to put the data at its stored location.
128 * @param expiration when will this result expire?
129 * @param data payload to store
130 * @param data_size size of the @a data
133 (*GDS_DATACACHE_SuccessorCallback)(void *cls,
134 enum GNUNET_DHT_RouteOption options,
135 const struct GNUNET_HashCode *key,
136 enum GNUNET_BLOCK_Type type,
137 unsigned int put_path_length,
138 const struct GNUNET_PeerIdentity *put_path,
139 struct GNUNET_TIME_Absolute expiration,
145 * Handle a request for data close to a key that we have received from
148 * @param key the location at which the peer is looking for data that is close
149 * @param cb function to call with the result
150 * @param cb_cls closure for @a cb
153 GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key,
154 GDS_DATACACHE_SuccessorCallback cb,
159 * Initialize datacache subsystem.
162 GDS_DATACACHE_init (void);
166 * Shutdown datacache subsystem.
169 GDS_DATACACHE_done (void);