2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 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 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file fs/gnunet-service-fs_pr.h
23 * @brief API to handle pending requests
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_FS_PR_H
27 #define GNUNET_SERVICE_FS_PR_H
29 #include "gnunet-service-fs.h"
33 * Options for pending requests (bits to be ORed).
35 enum GSF_PendingRequestOptions
39 * No special options (P2P-default).
44 * Request must only be processed locally.
46 GSF_PRO_LOCAL_ONLY = 1,
49 * Request must only be forwarded (no routing)
51 GSF_PRO_FORWARD_ONLY = 2,
54 * Request persists indefinitely (no expiration).
56 GSF_PRO_REQUEST_NEVER_EXPIRES = 4,
59 * Request is allowed to refresh bloomfilter and change mingle value.
61 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
64 * Request priority is allowed to be exceeded.
66 GSF_PRO_PRIORITY_UNLIMITED = 16,
69 * Option mask for typical local requests.
71 GSF_PRO_LOCAL_REQUEST =
72 (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES)
77 * Public data (in the sense of not encapsulated within
78 * 'gnunet-service-fs_pr', not in the sense of network-wide
79 * known) associated with each pending request.
81 struct GSF_PendingRequestData
85 * Primary query hash for this request.
87 GNUNET_HashCode query;
90 * Namespace to query, only set if the type is SBLOCK.
92 GNUNET_HashCode namespace;
95 * Identity of a peer hosting the content, only set if
96 * 'has_target' is GNUNET_YES.
98 struct GNUNET_PeerIdentity target;
101 * Fields for the plan module to track a DLL with the request.
103 struct GSF_RequestPlanReference *rpr_head;
106 * Fields for the plan module to track a DLL with the request.
108 struct GSF_RequestPlanReference *rpr_tail;
111 * Current TTL for the request.
113 struct GNUNET_TIME_Absolute ttl;
116 * When did we start with the request.
118 struct GNUNET_TIME_Absolute start_time;
121 * Desired anonymity level.
123 uint32_t anonymity_level;
126 * Priority that this request (still) has for us.
131 * Priority that this request (originally) had for us.
133 uint32_t original_priority;
136 * Options for the request.
138 enum GSF_PendingRequestOptions options;
141 * Type of the requested block.
143 enum GNUNET_BLOCK_Type type;
146 * Number of results we have found for this request so far.
148 unsigned int results_found;
151 * Is the 'target' value set to a valid peer identity?
156 * Has this request been started yet (local/p2p operations)? Or are
157 * we still constructing it?
165 * Handle a reply to a pending request. Also called if a request
166 * expires (then with data == NULL). The handler may be called
167 * many times (depending on the request type), but will not be
168 * called during or after a call to GSF_pending_request_cancel
169 * and will also not be called anymore after a call signalling
172 * @param cls user-specified closure
173 * @param eval evaluation of the result
174 * @param pr handle to the original pending request
175 * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown"
176 * @param expiration when does 'data' expire?
177 * @param type type of the block
178 * @param data response data, NULL on request expiration
179 * @param data_len number of bytes in data
181 typedef void (*GSF_PendingRequestReplyHandler) (void *cls,
183 GNUNET_BLOCK_EvaluationResult
185 struct GSF_PendingRequest * pr,
186 uint32_t reply_anonymity_level,
187 struct GNUNET_TIME_Absolute
189 enum GNUNET_BLOCK_Type type,
195 * Create a new pending request.
197 * @param options request options
198 * @param type type of the block that is being requested
199 * @param query key for the lookup
200 * @param namespace namespace to lookup, NULL for no namespace
201 * @param target preferred target for the request, NULL for none
202 * @param bf_data raw data for bloom filter for known replies, can be NULL
203 * @param bf_size number of bytes in bf_data
204 * @param mingle mingle value for bf
205 * @param anonymity_level desired anonymity level
206 * @param priority maximum outgoing cummulative request priority to use
207 * @param ttl current time-to-live for the request
208 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
209 * reference counter is taken over by this function
210 * @param origin_pid peer ID of origin of query (do not loop back)
211 * @param replies_seen hash codes of known local replies
212 * @param replies_seen_count size of the 'replies_seen' array
213 * @param rh handle to call when we get a reply
214 * @param rh_cls closure for rh
215 * @return handle for the new pending request
217 struct GSF_PendingRequest *
218 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
219 enum GNUNET_BLOCK_Type type,
220 const GNUNET_HashCode * query,
221 const GNUNET_HashCode * namespace,
222 const struct GNUNET_PeerIdentity *target,
223 const char *bf_data, size_t bf_size,
224 uint32_t mingle, uint32_t anonymity_level,
225 uint32_t priority, int32_t ttl,
226 GNUNET_PEER_Id sender_pid,
227 GNUNET_PEER_Id origin_pid,
228 const GNUNET_HashCode * replies_seen,
229 unsigned int replies_seen_count,
230 GSF_PendingRequestReplyHandler rh, void *rh_cls);
234 * Update a given pending request with additional replies
235 * that have been seen.
237 * @param pr request to update
238 * @param replies_seen hash codes of replies that we've seen
239 * @param replies_seen_count size of the replies_seen array
242 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
243 const GNUNET_HashCode * replies_seen,
244 unsigned int replies_seen_count);
248 * Obtain the public data associated with a pending request
250 * @param pr pending request
251 * @return associated public data
253 struct GSF_PendingRequestData *
254 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
258 * Test if two pending requests are compatible (would generate
259 * the same query modulo filters and should thus be processed
262 * @param pra a pending request
263 * @param prb another pending request
264 * @return GNUNET_OK if the requests are compatible
267 GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
268 struct GSF_PendingRequest *prb);
272 * Generate the message corresponding to the given pending request for
273 * transmission to other peers (or at least determine its size).
275 * @param pr request to generate the message for
276 * @param buf_size number of bytes available in buf
277 * @param buf where to copy the message (can be NULL)
278 * @return number of bytes needed (if buf_size too small) or used
281 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
282 size_t buf_size, void *buf);
286 * Explicitly cancel a pending request.
288 * @param pr request to cancel
289 * @param full_cleanup fully purge the request
292 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup);
296 * Signature of function called on each request.
297 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
300 * @param key query for the request
301 * @param pr handle to the pending request
302 * @return GNUNET_YES to continue to iterate
304 typedef int (*GSF_PendingRequestIterator) (void *cls,
305 const GNUNET_HashCode * key,
306 struct GSF_PendingRequest * pr);
310 * Iterate over all pending requests.
312 * @param it function to call for each request
313 * @param cls closure for it
316 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls);
320 * Handle P2P "CONTENT" message. Checks that the message is
321 * well-formed and then checks if there are any pending requests for
322 * this content and possibly passes it on (to local clients or other
323 * peers). Does NOT perform migration (content caching at this peer).
325 * @param cp the other peer involved (sender or receiver, NULL
326 * for loopback messages where we are both sender and receiver)
327 * @param message the actual message
328 * @return GNUNET_OK if the message was well-formed,
329 * GNUNET_SYSERR if the message was malformed (close connection,
330 * do not cache under any circumstances)
333 GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
334 const struct GNUNET_MessageHeader *message);
338 * Consider looking up the data in the DHT (anonymity-level permitting).
340 * @param pr the pending request to process
343 GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
347 * Function to be called after we're done processing
348 * replies from the local lookup.
351 * @param pr the pending request we were processing
352 * @param result final datastore lookup result
354 typedef void (*GSF_LocalLookupContinuation) (void *cls,
355 struct GSF_PendingRequest * pr,
356 enum GNUNET_BLOCK_EvaluationResult
361 * Look up the request in the local datastore.
363 * @param pr the pending request to process
364 * @param cont function to call at the end
365 * @param cont_cls closure for cont
368 GSF_local_lookup_ (struct GSF_PendingRequest *pr,
369 GSF_LocalLookupContinuation cont, void *cont_cls);
373 * Is the given target a legitimate peer for forwarding the given request?
377 * @return GNUNET_YES if this request could be forwarded to the given peer
380 GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
381 const struct GNUNET_PeerIdentity *target);
386 * Setup the subsystem.
389 GSF_pending_request_init_ (void);
393 * Shutdown the subsystem.
396 GSF_pending_request_done_ (void);
400 /* end of gnunet-service-fs_pr.h */