diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-09-26 20:38:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-09-26 20:38:48 +0000 |
commit | b77a243b51a385d52250d31a285669b7ad3aed20 (patch) | |
tree | 8790ee92b5a15c087d8c3563a5a25a6c7364dfc0 /src/include | |
parent | f6618c3d5bf77c8e642039233b44bb9be3177dcd (diff) | |
download | gnunet-b77a243b51a385d52250d31a285669b7ad3aed20.tar.gz gnunet-b77a243b51a385d52250d31a285669b7ad3aed20.zip |
add
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_dht_service_new.h | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/src/include/gnunet_dht_service_new.h b/src/include/gnunet_dht_service_new.h new file mode 100644 index 000000000..e180ad554 --- /dev/null +++ b/src/include/gnunet_dht_service_new.h | |||
@@ -0,0 +1,261 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2004, 2005, 2006, 2008, 2009, 2011 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_dht_service.h | ||
23 | * @brief API to the DHT service | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_DHT_SERVICE_H | ||
28 | #define GNUNET_DHT_SERVICE_H | ||
29 | |||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_block_lib.h" | ||
32 | #include "gnunet_hello_lib.h" | ||
33 | |||
34 | #ifdef __cplusplus | ||
35 | extern "C" | ||
36 | { | ||
37 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
38 | } | ||
39 | #endif | ||
40 | #endif | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Connection to the DHT service. | ||
45 | */ | ||
46 | struct GNUNET_DHT_Handle; | ||
47 | |||
48 | /** | ||
49 | * Handle to control a get operation. | ||
50 | */ | ||
51 | struct GNUNET_DHT_GetHandle; | ||
52 | |||
53 | /** | ||
54 | * Handle to control a find peer operation. | ||
55 | */ | ||
56 | struct GNUNET_DHT_FindPeerHandle; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Options for routing. | ||
61 | */ | ||
62 | enum GNUNET_DHT_RouteOption | ||
63 | { | ||
64 | /** | ||
65 | * Default. Do nothing special. | ||
66 | */ | ||
67 | GNUNET_DHT_RO_NONE = 0, | ||
68 | |||
69 | /** | ||
70 | * Each peer along the way should look at 'enc' (otherwise | ||
71 | * only the k-peers closest to the key should look at it). | ||
72 | */ | ||
73 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1, | ||
74 | |||
75 | /** | ||
76 | * We should keep track of the route that the message | ||
77 | * took in the P2P network. | ||
78 | */ | ||
79 | GNUNET_DHT_RO_RECORD_ROUTE = 2, | ||
80 | |||
81 | /** | ||
82 | * Possible message option for query key randomization. | ||
83 | */ | ||
84 | GNUNET_DHT_RO_BART = 4 | ||
85 | }; | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Initialize the connection with the DHT service. | ||
90 | * | ||
91 | * @param cfg configuration to use | ||
92 | * @param ht_len size of the internal hash table to use for | ||
93 | * processing multiple GET/FIND requests in parallel | ||
94 | * @return NULL on error | ||
95 | */ | ||
96 | struct GNUNET_DHT_Handle * | ||
97 | GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
98 | unsigned int ht_len); | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Shutdown connection with the DHT service. | ||
103 | * | ||
104 | * @param handle connection to shut down | ||
105 | */ | ||
106 | void | ||
107 | GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle); | ||
108 | |||
109 | |||
110 | /* *************** Standard API: get and put ******************* */ | ||
111 | |||
112 | /** | ||
113 | * Perform a PUT operation storing data in the DHT. | ||
114 | * | ||
115 | * @param handle handle to DHT service | ||
116 | * @param key the key to store under | ||
117 | * @param desired_replication_level estimate of how many | ||
118 | * nearest peers this request should reach | ||
119 | * @param options routing options for this message | ||
120 | * @param type type of the value | ||
121 | * @param size number of bytes in data; must be less than 64k | ||
122 | * @param data the data to store | ||
123 | * @param exp desired expiration time for the value | ||
124 | * @param timeout how long to wait for transmission of this request | ||
125 | * @param cont continuation to call when done (transmitting request to service) | ||
126 | * @param cont_cls closure for cont | ||
127 | */ | ||
128 | void | ||
129 | GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key, | ||
130 | uint32_t desired_replication_level, | ||
131 | enum GNUNET_DHT_RouteOption options, | ||
132 | enum GNUNET_BLOCK_Type type, size_t size, const char *data, | ||
133 | struct GNUNET_TIME_Absolute exp, | ||
134 | struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont, | ||
135 | void *cont_cls); | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Iterator called on each result obtained for a DHT | ||
140 | * operation that expects a reply | ||
141 | * | ||
142 | * @param cls closure | ||
143 | * @param exp when will this value expire | ||
144 | * @param key key of the result | ||
145 | * @param get_path NULL-terminated array of pointers | ||
146 | * to the peers on reverse GET path (or NULL if not recorded) | ||
147 | * @param put_path NULL-terminated array of pointers | ||
148 | * to the peers on the PUT path (or NULL if not recorded) | ||
149 | * @param type type of the result | ||
150 | * @param size number of bytes in data | ||
151 | * @param data pointer to the result data | ||
152 | */ | ||
153 | typedef void (*GNUNET_DHT_GetIterator) (void *cls, | ||
154 | struct GNUNET_TIME_Absolute exp, | ||
155 | const GNUNET_HashCode * key, | ||
156 | const struct GNUNET_PeerIdentity * | ||
157 | const *get_path, | ||
158 | const struct GNUNET_PeerIdentity * | ||
159 | const *put_path, | ||
160 | enum GNUNET_BLOCK_Type type, | ||
161 | size_t size, const void *data); | ||
162 | |||
163 | |||
164 | |||
165 | /** | ||
166 | * Perform an asynchronous GET operation on the DHT identified. See | ||
167 | * also "GNUNET_BLOCK_evaluate". | ||
168 | * | ||
169 | * @param handle handle to the DHT service | ||
170 | * @param timeout how long to wait for transmission of this request to the service | ||
171 | * @param type expected type of the response object | ||
172 | * @param key the key to look up | ||
173 | * @param desired_replication_level estimate of how many | ||
174 | nearest peers this request should reach | ||
175 | * @param options routing options for this message | ||
176 | * @param bf bloom filter associated with query (can be NULL) | ||
177 | * @param bf_mutator mutation value for bf | ||
178 | * @param xquery extended query data (can be NULL, depending on type) | ||
179 | * @param xquery_size number of bytes in xquery | ||
180 | * @param iter function to call on each result | ||
181 | * @param iter_cls closure for iter | ||
182 | * | ||
183 | * @return handle to stop the async get | ||
184 | */ | ||
185 | struct GNUNET_DHT_GetHandle * | ||
186 | GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, | ||
187 | struct GNUNET_TIME_Relative timeout, | ||
188 | enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, | ||
189 | uint32_t desired_replication_level, | ||
190 | enum GNUNET_DHT_RouteOption options, | ||
191 | const struct GNUNET_CONTAINER_BloomFilter *bf, | ||
192 | int32_t bf_mutator, const void *xquery, | ||
193 | size_t xquery_size, GNUNET_DHT_GetIterator iter, | ||
194 | void *iter_cls); | ||
195 | |||
196 | |||
197 | /** | ||
198 | * Stop async DHT-get. Frees associated resources. | ||
199 | * | ||
200 | * @param get_handle GET operation to stop. | ||
201 | * | ||
202 | * On return get_handle will no longer be valid, caller | ||
203 | * must not use again!!! | ||
204 | */ | ||
205 | void | ||
206 | GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle); | ||
207 | |||
208 | |||
209 | /* ******** Special high-level API for finding peers *********** */ | ||
210 | |||
211 | /** | ||
212 | * Iterator called on each result obtained from a find peer | ||
213 | * operation | ||
214 | * | ||
215 | * @param cls closure | ||
216 | * @param peer hello of a target (peer near key) | ||
217 | */ | ||
218 | typedef void (*GNUNET_DHT_FindPeerProcessor) (void *cls, | ||
219 | const struct GNUNET_HELLO_Message | ||
220 | * peer); | ||
221 | |||
222 | |||
223 | /** | ||
224 | * Perform an asynchronous FIND PEER operation on the DHT. | ||
225 | * | ||
226 | * @param handle handle to the DHT service | ||
227 | * @param timeout timeout for this request to be sent to the | ||
228 | * service | ||
229 | * @param key the key to look up | ||
230 | * @param options routing options for this message | ||
231 | * @param proc function to call on each result | ||
232 | * @param proc_cls closure for proc | ||
233 | * @return handle to stop the async get, NULL on error | ||
234 | */ | ||
235 | struct GNUNET_DHT_FindPeerHandle * | ||
236 | GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *handle, | ||
237 | struct GNUNET_TIME_Relative timeout, | ||
238 | const GNUNET_HashCode * key, | ||
239 | enum GNUNET_DHT_RouteOption options, | ||
240 | GNUNET_DHT_FindPeerProcessor proc, void *proc_cls); | ||
241 | |||
242 | |||
243 | /** | ||
244 | * Stop async find peer. Frees associated resources. | ||
245 | * | ||
246 | * @param find_peer_handle GET operation to stop. | ||
247 | */ | ||
248 | void | ||
249 | GNUNET_DHT_find_peer_stop (struct GNUNET_DHT_FindPeerHandle *find_peer_handle); | ||
250 | |||
251 | |||
252 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
253 | { | ||
254 | #endif | ||
255 | #ifdef __cplusplus | ||
256 | } | ||
257 | #endif | ||
258 | |||
259 | |||
260 | #endif | ||
261 | /* gnunet_dht_service.h */ | ||