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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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
38 * No special options (P2P-default).
43 * Request must only be processed locally.
45 GSF_PRO_LOCAL_ONLY = 1,
48 * Request must only be forwarded (no routing)
50 GSF_PRO_FORWARD_ONLY = 2,
53 * Request persists indefinitely (no expiration).
55 GSF_PRO_REQUEST_NEVER_EXPIRES = 4,
58 * Request is allowed to refresh bloomfilter and change mingle value.
60 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
63 * Request priority is allowed to be exceeded.
65 GSF_PRO_PRIORITY_UNLIMITED = 16,
68 * Option mask for typical local requests.
70 GSF_PRO_LOCAL_REQUEST =
71 (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED
72 | 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
84 * Primary query hash for this request.
86 struct GNUNET_HashCode query;
89 * Identity of a peer hosting the content, otherwise NULl.
90 * Allocated after struct only if needed. Do not free!
92 const struct GNUNET_PeerIdentity *target;
95 * Fields for the plan module to track a DLL with the request.
97 struct GSF_PendingRequestPlanBijection *pr_head;
100 * Fields for the plan module to track a DLL with the request.
102 struct GSF_PendingRequestPlanBijection *pr_tail;
105 * Current TTL for the request.
107 struct GNUNET_TIME_Absolute ttl;
110 * When did we start with the request.
112 struct GNUNET_TIME_Absolute start_time;
115 * Desired anonymity level.
117 uint32_t anonymity_level;
120 * Priority that this request (still) has for us.
125 * Priority that this request (originally) had for us.
127 uint32_t original_priority;
130 * Counter for how often this request has been transmitted (estimate,
131 * because we might have the same request pending for multiple clients,
132 * and of course because a transmission may have failed at a lower
135 uint32_t num_transmissions;
138 * How much respect did we (in total) offer for this request so far (estimate,
139 * because we might have the same request pending for multiple clients,
140 * and of course because a transmission may have failed at a lower
143 uint32_t respect_offered;
146 * Options for the request.
148 enum GSF_PendingRequestOptions options;
151 * Type of the requested block.
153 enum GNUNET_BLOCK_Type type;
156 * Number of results we have found for this request so far.
158 unsigned int results_found;
161 * Has this request been started yet (local/p2p operations)? Or are
162 * 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
194 enum GNUNET_BLOCK_Type type,
200 * Create a new pending request.
202 * @param options request options
203 * @param type type of the block that is being requested
204 * @param query key for the lookup
205 * @param target preferred target for the request, NULL for none
206 * @param bf_data raw data for bloom filter for known replies, can be NULL
207 * @param bf_size number of bytes in bf_data
208 * @param mingle mingle value for bf
209 * @param anonymity_level desired anonymity level
210 * @param priority maximum outgoing cummulative request priority to use
211 * @param ttl current time-to-live for the request
212 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
213 * reference counter is taken over by this function
214 * @param origin_pid peer ID of origin of query (do not loop back)
215 * @param replies_seen hash codes of known local replies
216 * @param replies_seen_count size of the 'replies_seen' array
217 * @param rh handle to call when we get a reply
218 * @param rh_cls closure for rh
219 * @return handle for the new pending request
221 struct GSF_PendingRequest *
222 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
223 enum GNUNET_BLOCK_Type type,
224 const struct GNUNET_HashCode *query,
225 const struct GNUNET_PeerIdentity *target,
229 uint32_t anonymity_level,
232 GNUNET_PEER_Id sender_pid,
233 GNUNET_PEER_Id origin_pid,
234 const struct GNUNET_HashCode *replies_seen,
235 unsigned int replies_seen_count,
236 GSF_PendingRequestReplyHandler rh,
241 * Update a given pending request with additional replies
242 * that have been seen.
244 * @param pr request to update
245 * @param replies_seen hash codes of replies that we've seen
246 * @param replies_seen_count size of the @a replies_seen array
249 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
250 const struct GNUNET_HashCode *replies_seen,
251 unsigned int replies_seen_count);
255 * Obtain the public data associated with a pending request
257 * @param pr pending request
258 * @return associated public data
260 struct GSF_PendingRequestData *
261 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
265 * Check if the given request is still active.
267 * @param pr pending request
268 * @return #GNUNET_YES if the request is still active
271 GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr);
275 * Test if two pending requests are compatible (would generate
276 * the same query modulo filters and should thus be processed
279 * @param pra a pending request
280 * @param prb another pending request
281 * @return #GNUNET_OK if the requests are compatible
284 GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
285 struct GSF_PendingRequest *prb);
289 * Generate the message corresponding to the given pending request for
290 * transmission to other peers.
292 * @param pr request to generate the message for
293 * @return envelope with the request message
295 struct GNUNET_MQ_Envelope *
296 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr);
300 * Explicitly cancel a pending request.
302 * @param pr request to cancel
303 * @param full_cleanup fully purge the request
306 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
311 * Signature of function called on each request.
312 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
315 * @param key query for the request
316 * @param pr handle to the pending request
317 * @return #GNUNET_YES to continue to iterate
320 (*GSF_PendingRequestIterator) (void *cls,
321 const struct GNUNET_HashCode *key,
322 struct GSF_PendingRequest *pr);
326 * Iterate over all pending requests.
328 * @param it function to call for each request
329 * @param cls closure for it
332 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
337 * Handle P2P "CONTENT" message. Checks that the message is
338 * well-formed and then checks if there are any pending requests for
339 * this content and possibly passes it on (to local clients or other
340 * peers). Does NOT perform migration (content caching at this peer).
342 * @param cls the other peer involved (sender)
343 * @param put the actual message
346 handle_p2p_put (void *cls,
347 const struct PutMessage *put);
351 * Consider looking up the data in the DHT (anonymity-level permitting).
353 * @param pr the pending request to process
356 GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
360 * Consider downloading via cadet (if possible)
362 * @param pr the pending request to process
365 GSF_cadet_lookup_ (struct GSF_PendingRequest *pr);
369 * Function to be called after we're done processing
370 * replies from the local lookup.
373 * @param pr the pending request we were processing
374 * @param result final datastore lookup result
377 (*GSF_LocalLookupContinuation) (void *cls,
378 struct GSF_PendingRequest *pr,
379 enum GNUNET_BLOCK_EvaluationResult result);
383 * Look up the request in the local datastore.
385 * @param pr the pending request to process
386 * @param cont function to call at the end
387 * @param cont_cls closure for @a cont
390 GSF_local_lookup_ (struct GSF_PendingRequest *pr,
391 GSF_LocalLookupContinuation cont,
396 * Is the given target a legitimate peer for forwarding the given request?
400 * @return #GNUNET_YES if this request could be forwarded to the given peer
403 GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
404 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 */