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 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.
17 * @file fs/gnunet-service-fs_pr.h
18 * @brief API to handle pending requests
19 * @author Christian Grothoff
21 #ifndef GNUNET_SERVICE_FS_PR_H
22 #define GNUNET_SERVICE_FS_PR_H
24 #include "gnunet-service-fs.h"
28 * Options for pending requests (bits to be ORed).
30 enum GSF_PendingRequestOptions
34 * No special options (P2P-default).
39 * Request must only be processed locally.
41 GSF_PRO_LOCAL_ONLY = 1,
44 * Request must only be forwarded (no routing)
46 GSF_PRO_FORWARD_ONLY = 2,
49 * Request persists indefinitely (no expiration).
51 GSF_PRO_REQUEST_NEVER_EXPIRES = 4,
54 * Request is allowed to refresh bloomfilter and change mingle value.
56 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
59 * Request priority is allowed to be exceeded.
61 GSF_PRO_PRIORITY_UNLIMITED = 16,
64 * Option mask for typical local requests.
66 GSF_PRO_LOCAL_REQUEST =
67 (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED | GSF_PRO_REQUEST_NEVER_EXPIRES)
72 * Public data (in the sense of not encapsulated within
73 * 'gnunet-service-fs_pr', not in the sense of network-wide
74 * known) associated with each pending request.
76 struct GSF_PendingRequestData
80 * Primary query hash for this request.
82 struct GNUNET_HashCode query;
85 * Identity of a peer hosting the content, otherwise NULl.
86 * Allocated after struct only if needed. Do not free!
88 const struct GNUNET_PeerIdentity *target;
91 * Fields for the plan module to track a DLL with the request.
93 struct GSF_PendingRequestPlanBijection *pr_head;
96 * Fields for the plan module to track a DLL with the request.
98 struct GSF_PendingRequestPlanBijection *pr_tail;
101 * Current TTL for the request.
103 struct GNUNET_TIME_Absolute ttl;
106 * When did we start with the request.
108 struct GNUNET_TIME_Absolute start_time;
111 * Desired anonymity level.
113 uint32_t anonymity_level;
116 * Priority that this request (still) has for us.
121 * Priority that this request (originally) had for us.
123 uint32_t original_priority;
126 * Counter for how often this request has been transmitted (estimate,
127 * because we might have the same request pending for multiple clients,
128 * and of course because a transmission may have failed at a lower
131 uint32_t num_transmissions;
134 * How much respect did we (in total) offer for this request so far (estimate,
135 * because we might have the same request pending for multiple clients,
136 * and of course because a transmission may have failed at a lower
139 uint32_t respect_offered;
142 * Options for the request.
144 enum GSF_PendingRequestOptions options;
147 * Type of the requested block.
149 enum GNUNET_BLOCK_Type type;
152 * Number of results we have found for this request so far.
154 unsigned int results_found;
157 * Has this request been started yet (local/p2p operations)? Or are
158 * we still constructing it?
166 * Handle a reply to a pending request. Also called if a request
167 * expires (then with data == NULL). The handler may be called
168 * many times (depending on the request type), but will not be
169 * called during or after a call to GSF_pending_request_cancel
170 * and will also not be called anymore after a call signalling
173 * @param cls user-specified closure
174 * @param eval evaluation of the result
175 * @param pr handle to the original pending request
176 * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown"
177 * @param expiration when does @a data expire?
178 * @param last_transmission the last time we've tried to get this block (FOREVER if unknown)
179 * @param type type of the block
180 * @param data response data, NULL on request expiration
181 * @param data_len number of bytes in @a data
184 (*GSF_PendingRequestReplyHandler) (void *cls,
185 enum GNUNET_BLOCK_EvaluationResult eval,
186 struct GSF_PendingRequest *pr,
187 uint32_t reply_anonymity_level,
188 struct GNUNET_TIME_Absolute expiration,
189 struct GNUNET_TIME_Absolute last_transmission,
190 enum GNUNET_BLOCK_Type type,
196 * Create a new pending request.
198 * @param options request options
199 * @param type type of the block that is being requested
200 * @param query key for the lookup
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 struct GNUNET_HashCode *query,
221 const struct GNUNET_PeerIdentity *target,
225 uint32_t anonymity_level,
228 GNUNET_PEER_Id sender_pid,
229 GNUNET_PEER_Id origin_pid,
230 const struct GNUNET_HashCode *replies_seen,
231 unsigned int replies_seen_count,
232 GSF_PendingRequestReplyHandler rh,
237 * Update a given pending request with additional replies
238 * that have been seen.
240 * @param pr request to update
241 * @param replies_seen hash codes of replies that we've seen
242 * @param replies_seen_count size of the @a replies_seen array
245 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
246 const struct GNUNET_HashCode *replies_seen,
247 unsigned int replies_seen_count);
251 * Obtain the public data associated with a pending request
253 * @param pr pending request
254 * @return associated public data
256 struct GSF_PendingRequestData *
257 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
261 * Check if the given request is still active.
263 * @param pr pending request
264 * @return #GNUNET_YES if the request is still active
267 GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr);
271 * Test if two pending requests are compatible (would generate
272 * the same query modulo filters and should thus be processed
275 * @param pra a pending request
276 * @param prb another pending request
277 * @return #GNUNET_OK if the requests are compatible
280 GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
281 struct GSF_PendingRequest *prb);
285 * Generate the message corresponding to the given pending request for
286 * transmission to other peers.
288 * @param pr request to generate the message for
289 * @return envelope with the request message
291 struct GNUNET_MQ_Envelope *
292 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr);
296 * Explicitly cancel a pending request.
298 * @param pr request to cancel
299 * @param full_cleanup fully purge the request
302 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
307 * Signature of function called on each request.
308 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
311 * @param key query for the request
312 * @param pr handle to the pending request
313 * @return #GNUNET_YES to continue to iterate
316 (*GSF_PendingRequestIterator) (void *cls,
317 const struct GNUNET_HashCode *key,
318 struct GSF_PendingRequest *pr);
322 * Iterate over all pending requests.
324 * @param it function to call for each request
325 * @param cls closure for it
328 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
333 * Handle P2P "CONTENT" message. Checks that the message is
334 * well-formed and then checks if there are any pending requests for
335 * this content and possibly passes it on (to local clients or other
336 * peers). Does NOT perform migration (content caching at this peer).
338 * @param cls the other peer involved (sender)
339 * @param put the actual message
342 handle_p2p_put (void *cls,
343 const struct PutMessage *put);
347 * Consider looking up the data in the DHT (anonymity-level permitting).
349 * @param pr the pending request to process
352 GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
356 * Consider downloading via cadet (if possible)
358 * @param pr the pending request to process
361 GSF_cadet_lookup_ (struct GSF_PendingRequest *pr);
365 * Function to be called after we're done processing
366 * replies from the local lookup.
369 * @param pr the pending request we were processing
370 * @param result final datastore lookup result
373 (*GSF_LocalLookupContinuation) (void *cls,
374 struct GSF_PendingRequest *pr,
375 enum GNUNET_BLOCK_EvaluationResult result);
379 * Look up the request in the local datastore.
381 * @param pr the pending request to process
382 * @param cont function to call at the end
383 * @param cont_cls closure for @a cont
386 GSF_local_lookup_ (struct GSF_PendingRequest *pr,
387 GSF_LocalLookupContinuation cont,
392 * Is the given target a legitimate peer for forwarding the given request?
396 * @return #GNUNET_YES if this request could be forwarded to the given peer
399 GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
400 const struct GNUNET_PeerIdentity *target);
405 * Setup the subsystem.
408 GSF_pending_request_init_ (void);
412 * Shutdown the subsystem.
415 GSF_pending_request_done_ (void);
419 /* end of gnunet-service-fs_pr.h */