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
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 struct GNUNET_HashCode query;
90 * Identity of a peer hosting the content, otherwise NULl.
91 * Allocated after struct only if needed. Do not free!
93 const struct GNUNET_PeerIdentity *target;
96 * Fields for the plan module to track a DLL with the request.
98 struct GSF_PendingRequestPlanBijection *pr_head;
101 * Fields for the plan module to track a DLL with the request.
103 struct GSF_PendingRequestPlanBijection *pr_tail;
106 * Current TTL for the request.
108 struct GNUNET_TIME_Absolute ttl;
111 * When did we start with the request.
113 struct GNUNET_TIME_Absolute start_time;
116 * Desired anonymity level.
118 uint32_t anonymity_level;
121 * Priority that this request (still) has for us.
126 * Priority that this request (originally) had for us.
128 uint32_t original_priority;
131 * Counter for how often this request has been transmitted (estimate,
132 * because we might have the same request pending for multiple clients,
133 * and of course because a transmission may have failed at a lower
136 uint32_t num_transmissions;
139 * How much respect did we (in total) offer for this request so far (estimate,
140 * because we might have the same request pending for multiple clients,
141 * and of course because a transmission may have failed at a lower
144 uint32_t respect_offered;
147 * Options for the request.
149 enum GSF_PendingRequestOptions options;
152 * Type of the requested block.
154 enum GNUNET_BLOCK_Type type;
157 * Number of results we have found for this request so far.
159 unsigned int results_found;
162 * Has this request been started yet (local/p2p operations)? Or are
163 * we still constructing it?
171 * Handle a reply to a pending request. Also called if a request
172 * expires (then with data == NULL). The handler may be called
173 * many times (depending on the request type), but will not be
174 * called during or after a call to GSF_pending_request_cancel
175 * and will also not be called anymore after a call signalling
178 * @param cls user-specified closure
179 * @param eval evaluation of the result
180 * @param pr handle to the original pending request
181 * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown"
182 * @param expiration when does @a data expire?
183 * @param last_transmission the last time we've tried to get this block (FOREVER if unknown)
184 * @param type type of the block
185 * @param data response data, NULL on request expiration
186 * @param data_len number of bytes in @a data
189 (*GSF_PendingRequestReplyHandler) (void *cls,
190 enum GNUNET_BLOCK_EvaluationResult eval,
191 struct GSF_PendingRequest *pr,
192 uint32_t reply_anonymity_level,
193 struct GNUNET_TIME_Absolute expiration,
194 struct GNUNET_TIME_Absolute last_transmission,
195 enum GNUNET_BLOCK_Type type,
201 * Create a new pending request.
203 * @param options request options
204 * @param type type of the block that is being requested
205 * @param query key for the lookup
206 * @param target preferred target for the request, NULL for none
207 * @param bf_data raw data for bloom filter for known replies, can be NULL
208 * @param bf_size number of bytes in bf_data
209 * @param mingle mingle value for bf
210 * @param anonymity_level desired anonymity level
211 * @param priority maximum outgoing cummulative request priority to use
212 * @param ttl current time-to-live for the request
213 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
214 * reference counter is taken over by this function
215 * @param origin_pid peer ID of origin of query (do not loop back)
216 * @param replies_seen hash codes of known local replies
217 * @param replies_seen_count size of the 'replies_seen' array
218 * @param rh handle to call when we get a reply
219 * @param rh_cls closure for rh
220 * @return handle for the new pending request
222 struct GSF_PendingRequest *
223 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
224 enum GNUNET_BLOCK_Type type,
225 const struct GNUNET_HashCode *query,
226 const struct GNUNET_PeerIdentity *target,
230 uint32_t anonymity_level,
233 GNUNET_PEER_Id sender_pid,
234 GNUNET_PEER_Id origin_pid,
235 const struct GNUNET_HashCode *replies_seen,
236 unsigned int replies_seen_count,
237 GSF_PendingRequestReplyHandler rh,
242 * Update a given pending request with additional replies
243 * that have been seen.
245 * @param pr request to update
246 * @param replies_seen hash codes of replies that we've seen
247 * @param replies_seen_count size of the @a replies_seen array
250 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
251 const struct GNUNET_HashCode *replies_seen,
252 unsigned int replies_seen_count);
256 * Obtain the public data associated with a pending request
258 * @param pr pending request
259 * @return associated public data
261 struct GSF_PendingRequestData *
262 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
266 * Check if the given request is still active.
268 * @param pr pending request
269 * @return #GNUNET_YES if the request is still active
272 GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr);
276 * Test if two pending requests are compatible (would generate
277 * the same query modulo filters and should thus be processed
280 * @param pra a pending request
281 * @param prb another pending request
282 * @return #GNUNET_OK if the requests are compatible
285 GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
286 struct GSF_PendingRequest *prb);
290 * Generate the message corresponding to the given pending request for
291 * transmission to other peers.
293 * @param pr request to generate the message for
294 * @return envelope with the request message
296 struct GNUNET_MQ_Envelope *
297 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr);
301 * Explicitly cancel a pending request.
303 * @param pr request to cancel
304 * @param full_cleanup fully purge the request
307 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
312 * Signature of function called on each request.
313 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
316 * @param key query for the request
317 * @param pr handle to the pending request
318 * @return #GNUNET_YES to continue to iterate
321 (*GSF_PendingRequestIterator) (void *cls,
322 const struct GNUNET_HashCode *key,
323 struct GSF_PendingRequest *pr);
327 * Iterate over all pending requests.
329 * @param it function to call for each request
330 * @param cls closure for it
333 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
338 * Handle P2P "CONTENT" message. Checks that the message is
339 * well-formed and then checks if there are any pending requests for
340 * this content and possibly passes it on (to local clients or other
341 * peers). Does NOT perform migration (content caching at this peer).
343 * @param cls the other peer involved (sender)
344 * @param put the actual message
347 handle_p2p_put (void *cls,
348 const struct PutMessage *put);
352 * Consider looking up the data in the DHT (anonymity-level permitting).
354 * @param pr the pending request to process
357 GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
361 * Consider downloading via cadet (if possible)
363 * @param pr the pending request to process
366 GSF_cadet_lookup_ (struct GSF_PendingRequest *pr);
370 * Function to be called after we're done processing
371 * replies from the local lookup.
374 * @param pr the pending request we were processing
375 * @param result final datastore lookup result
378 (*GSF_LocalLookupContinuation) (void *cls,
379 struct GSF_PendingRequest *pr,
380 enum GNUNET_BLOCK_EvaluationResult result);
384 * Look up the request in the local datastore.
386 * @param pr the pending request to process
387 * @param cont function to call at the end
388 * @param cont_cls closure for @a cont
391 GSF_local_lookup_ (struct GSF_PendingRequest *pr,
392 GSF_LocalLookupContinuation cont,
397 * Is the given target a legitimate peer for forwarding the given request?
401 * @return #GNUNET_YES if this request could be forwarded to the given peer
404 GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
405 const struct GNUNET_PeerIdentity *target);
410 * Setup the subsystem.
413 GSF_pending_request_init_ (void);
417 * Shutdown the subsystem.
420 GSF_pending_request_done_ (void);
424 /* end of gnunet-service-fs_pr.h */