2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2008, 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_dht_service.h
23 * @brief API to the DHT service
24 * @author Christian Grothoff
27 #ifndef GNUNET_DHT_SERVICE_H
28 #define GNUNET_DHT_SERVICE_H
30 #include "gnunet_util_lib.h"
35 #if 0 /* keep Emacsens' auto-indent happy */
42 * Connection to the DHT service.
44 struct GNUNET_DHT_Handle;
48 * Initialize the connection with the DHT service.
50 * @param cfg configuration to use
51 * @param sched scheduler to use
52 * @param ht_len size of the internal hash table to use for
53 * processing multiple GET/FIND requests in parallel
54 * @return NULL on error
56 struct GNUNET_DHT_Handle *
57 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
58 const struct GNUNET_CONFIGURATION_Handle *cfg,
63 * Shutdown connection with the DHT service.
65 * @param h connection to shut down
68 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *h);
72 * Perform a PUT operation on the DHT identified by 'table' storing
73 * a binding of 'key' to 'value'. The peer does not have to be part
74 * of the table (if so, we will attempt to locate a peer that is!)
76 * @param h handle to DHT service
77 * @param key the key to store under
78 * @param type type of the value
79 * @param size number of bytes in data; must be less than 64k
80 * @param data the data to store
81 * @param exp desired expiration time for the value
82 * @param timeout when to abort with an error if we fail to get
83 * a confirmation for the PUT from the local DHT service
84 * @param cont continuation to call when done;
85 * reason will be TIMEOUT on error,
86 * reason will be PREREQ_DONE on success
87 * @param cont_cls closure for cont
90 GNUNET_DHT_put (struct GNUNET_DHT_Handle *h,
91 const GNUNET_HashCode * key,
95 struct GNUNET_TIME_Absolute exp,
96 struct GNUNET_TIME_Relative timeout,
97 GNUNET_SCHEDULER_Task cont,
102 * Handle to control a GET operation.
104 struct GNUNET_DHT_GetHandle;
108 * Iterator called on each result obtained for a GET
112 * @param exp when will this value expire
113 * @param key key of the result
114 * @param type type of the result
115 * @param size number of bytes in data
116 * @param data pointer to the result data
118 typedef void (*GNUNET_DHT_Iterator)(void *cls,
119 struct GNUNET_TIME_Absolute exp,
120 const GNUNET_HashCode * key,
128 * Perform an asynchronous GET operation on the DHT identified.
130 * @param h handle to the DHT service
131 * @param type expected type of the response object
132 * @param key the key to look up
133 * @param iter function to call on each result
134 * @param iter_cls closure for iter
135 * @return handle to stop the async get, NULL on error
137 struct GNUNET_DHT_GetHandle *
138 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *h,
140 const GNUNET_HashCode * key,
141 GNUNET_DHT_Iterator iter,
145 * Stop async DHT-get. Frees associated resources.
147 * @param get_handle GET operation to stop.
150 GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle);
154 * Iterator called on each result obtained from a FIND_PEER
158 * @param peer a peer that was located
159 * @param reply response generated by the peer (for example, a HELLO); or NULL
161 typedef void (*GNUNET_DHT_ReplyProcessor)(void *cls,
162 const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_MessageHeader *reply);
167 * Options for routing.
169 enum GNUNET_DHT_RouteOption
172 * Default. Do nothing special.
174 GNUNET_DHT_RO_NONE = 0,
177 * Each peer along the way should look at 'enc' (otherwise
178 * only the k-peers closest to the key should look at it).
180 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1
185 * Perform an asynchronous FIND_PEER operation on the DHT.
187 * @param handle handle to the DHT service
188 * @param key the key to look up
189 * @param desired_replication_level how many peers should ultimately receive
190 * this message (advisory only, target may be too high for the
191 * given DHT or not hit exactly).
192 * @param options options for routing
193 * @param enc send the encapsulated message to a peer close to the key
194 * @param iter function to call on each result, NULL if no replies are expected
195 * @param iter_cls closure for iter
196 * @param timeout when to abort with an error if we fail to get
197 * a confirmation for the PUT from the local DHT service
198 * @param cont continuation to call when done;
199 * reason will be TIMEOUT on error,
200 * reason will be PREREQ_DONE on success
201 * @param cont_cls closure for cont
202 * @return handle to stop the request
204 struct GNUNET_DHT_FindPeerHandle *
205 GNUNET_DHT_route_start (struct GNUNET_DHT_Handle *handle,
206 const GNUNET_HashCode *key,
207 unsigned int desired_replication_level,
208 enum GNUNET_DHT_RouteOption options,
209 const struct GNUNET_MessageHeader *enc,
210 struct GNUNET_TIME_Relative timeout,
211 GNUNET_DHT_ReplyProcessor iter,
213 GNUNET_SCHEDULER_Task cont,
217 GNUNET_DHT_route_stop (struct GNUNET_DHT_FindPeerHandle *fph);
220 #if 0 /* keep Emacsens' auto-indent happy */
229 /* gnunet_dht_service.h */