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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file fs/gnunet-service-fs_pr.h
21 * @brief API to handle pending requests
22 * @author Christian Grothoff
24 #ifndef GNUNET_SERVICE_FS_PR_H
25 #define GNUNET_SERVICE_FS_PR_H
27 #include "gnunet-service-fs.h"
31 * Options for pending requests (bits to be ORed).
33 enum GSF_PendingRequestOptions
37 * No special options (P2P-default).
42 * Request must only be processed locally.
44 GSF_PRO_LOCAL_ONLY = 1,
47 * Request must only be forwarded (no routing)
49 GSF_PRO_FORWARD_ONLY = 2,
52 * Request persists indefinitely (no expiration).
54 GSF_PRO_REQUEST_NEVER_EXPIRES = 4,
57 * Request is allowed to refresh bloomfilter and change mingle value.
59 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
62 * Request priority is allowed to be exceeded.
64 GSF_PRO_PRIORITY_UNLIMITED = 16,
67 * Option mask for typical local requests.
69 GSF_PRO_LOCAL_REQUEST =
70 (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES)
75 * Public data (in the sense of not encapsulated within
76 * 'gnunet-service-fs_pr', not in the sense of network-wide
77 * known) associated with each pending request.
79 struct GSF_PendingRequestData
83 * Primary query hash for this request.
85 struct GNUNET_HashCode query;
88 * Identity of a peer hosting the content, otherwise NULl.
89 * Allocated after struct only if needed. Do not free!
91 const struct GNUNET_PeerIdentity *target;
94 * Fields for the plan module to track a DLL with the request.
96 struct GSF_PendingRequestPlanBijection *pr_head;
99 * Fields for the plan module to track a DLL with the request.
101 struct GSF_PendingRequestPlanBijection *pr_tail;
104 * Current TTL for the request.
106 struct GNUNET_TIME_Absolute ttl;
109 * When did we start with the request.
111 struct GNUNET_TIME_Absolute start_time;
114 * Desired anonymity level.
116 uint32_t anonymity_level;
119 * Priority that this request (still) has for us.
124 * Priority that this request (originally) had for us.
126 uint32_t original_priority;
129 * Counter for how often this request has been transmitted (estimate,
130 * because we might have the same request pending for multiple clients,
131 * and of course because a transmission may have failed at a lower
134 uint32_t num_transmissions;
137 * How much respect did we (in total) offer for this request so far (estimate,
138 * because we might have the same request pending for multiple clients,
139 * and of course because a transmission may have failed at a lower
142 uint32_t respect_offered;
145 * Options for the request.
147 enum GSF_PendingRequestOptions options;
150 * Type of the requested block.
152 enum GNUNET_BLOCK_Type type;
155 * Number of results we have found for this request so far.
157 unsigned int results_found;
160 * Has this request been started yet (local/p2p operations)? Or are
161 * we still constructing it?
169 * Handle a reply to a pending request. Also called if a request
170 * expires (then with data == NULL). The handler may be called
171 * many times (depending on the request type), but will not be
172 * called during or after a call to GSF_pending_request_cancel
173 * and will also not be called anymore after a call signalling
176 * @param cls user-specified closure
177 * @param eval evaluation of the result
178 * @param pr handle to the original pending request
179 * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown"
180 * @param expiration when does @a data expire?
181 * @param last_transmission the last time we've tried to get this block (FOREVER if unknown)
182 * @param type type of the block
183 * @param data response data, NULL on request expiration
184 * @param data_len number of bytes in @a data
187 (*GSF_PendingRequestReplyHandler) (void *cls,
188 enum GNUNET_BLOCK_EvaluationResult eval,
189 struct GSF_PendingRequest *pr,
190 uint32_t reply_anonymity_level,
191 struct GNUNET_TIME_Absolute expiration,
192 struct GNUNET_TIME_Absolute last_transmission,
193 enum GNUNET_BLOCK_Type type,
199 * Create a new pending request.
201 * @param options request options
202 * @param type type of the block that is being requested
203 * @param query key for the lookup
204 * @param target preferred target for the request, NULL for none
205 * @param bf_data raw data for bloom filter for known replies, can be NULL
206 * @param bf_size number of bytes in bf_data
207 * @param mingle mingle value for bf
208 * @param anonymity_level desired anonymity level
209 * @param priority maximum outgoing cummulative request priority to use
210 * @param ttl current time-to-live for the request
211 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
212 * reference counter is taken over by this function
213 * @param origin_pid peer ID of origin of query (do not loop back)
214 * @param replies_seen hash codes of known local replies
215 * @param replies_seen_count size of the 'replies_seen' array
216 * @param rh handle to call when we get a reply
217 * @param rh_cls closure for rh
218 * @return handle for the new pending request
220 struct GSF_PendingRequest *
221 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
222 enum GNUNET_BLOCK_Type type,
223 const struct GNUNET_HashCode *query,
224 const struct GNUNET_PeerIdentity *target,
228 uint32_t anonymity_level,
231 GNUNET_PEER_Id sender_pid,
232 GNUNET_PEER_Id origin_pid,
233 const struct GNUNET_HashCode *replies_seen,
234 unsigned int replies_seen_count,
235 GSF_PendingRequestReplyHandler rh,
240 * Update a given pending request with additional replies
241 * that have been seen.
243 * @param pr request to update
244 * @param replies_seen hash codes of replies that we've seen
245 * @param replies_seen_count size of the @a replies_seen array
248 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
249 const struct GNUNET_HashCode *replies_seen,
250 unsigned int replies_seen_count);
254 * Obtain the public data associated with a pending request
256 * @param pr pending request
257 * @return associated public data
259 struct GSF_PendingRequestData *
260 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
264 * Check if the given request is still active.
266 * @param pr pending request
267 * @return #GNUNET_YES if the request is still active
270 GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr);
274 * Test if two pending requests are compatible (would generate
275 * the same query modulo filters and should thus be processed
278 * @param pra a pending request
279 * @param prb another pending request
280 * @return #GNUNET_OK if the requests are compatible
283 GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
284 struct GSF_PendingRequest *prb);
288 * Generate the message corresponding to the given pending request for
289 * transmission to other peers.
291 * @param pr request to generate the message for
292 * @return envelope with the request message
294 struct GNUNET_MQ_Envelope *
295 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr);
299 * Explicitly cancel a pending request.
301 * @param pr request to cancel
302 * @param full_cleanup fully purge the request
305 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
310 * Signature of function called on each request.
311 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
314 * @param key query for the request
315 * @param pr handle to the pending request
316 * @return #GNUNET_YES to continue to iterate
319 (*GSF_PendingRequestIterator) (void *cls,
320 const struct GNUNET_HashCode *key,
321 struct GSF_PendingRequest *pr);
325 * Iterate over all pending requests.
327 * @param it function to call for each request
328 * @param cls closure for it
331 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
336 * Handle P2P "CONTENT" message. Checks that the message is
337 * well-formed and then checks if there are any pending requests for
338 * this content and possibly passes it on (to local clients or other
339 * peers). Does NOT perform migration (content caching at this peer).
341 * @param cls the other peer involved (sender)
342 * @param put the actual message
345 handle_p2p_put (void *cls,
346 const struct PutMessage *put);
350 * Consider looking up the data in the DHT (anonymity-level permitting).
352 * @param pr the pending request to process
355 GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
359 * Consider downloading via cadet (if possible)
361 * @param pr the pending request to process
364 GSF_cadet_lookup_ (struct GSF_PendingRequest *pr);
368 * Function to be called after we're done processing
369 * replies from the local lookup.
372 * @param pr the pending request we were processing
373 * @param result final datastore lookup result
376 (*GSF_LocalLookupContinuation) (void *cls,
377 struct GSF_PendingRequest *pr,
378 enum GNUNET_BLOCK_EvaluationResult result);
382 * Look up the request in the local datastore.
384 * @param pr the pending request to process
385 * @param cont function to call at the end
386 * @param cont_cls closure for @a cont
389 GSF_local_lookup_ (struct GSF_PendingRequest *pr,
390 GSF_LocalLookupContinuation cont,
395 * Is the given target a legitimate peer for forwarding the given request?
399 * @return #GNUNET_YES if this request could be forwarded to the given peer
402 GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
403 const struct GNUNET_PeerIdentity *target);
408 * Setup the subsystem.
411 GSF_pending_request_init_ (void);
415 * Shutdown the subsystem.
418 GSF_pending_request_done_ (void);
422 /* end of gnunet-service-fs_pr.h */